Highcharts 如何在一页上获得两个高图表?
我有两个图表,我正试图加载到同一页上不同的div上,它们是相似的,但一个是向下钻取,另一个不是。我试着用Highcharts 如何在一页上获得两个高图表?,highcharts,Highcharts,我有两个图表,我正试图加载到同一页上不同的div上,它们是相似的,但一个是向下钻取,另一个不是。我试着用var chart=$('#review').highcharts({但是它不起作用 以下是两个图表: $(function () { var colors = Highcharts.getOptions().colors, categories = ['Metric 1', 'Metric 2', 'Metric 3','metric 4'],
var chart=$('#review').highcharts({
但是它不起作用
以下是两个图表:
$(function () {
var colors = Highcharts.getOptions().colors,
categories = ['Metric 1', 'Metric 2', 'Metric 3','metric 4'],
name = 'Votes',
data = [{
y: 1,
color: colors[0],
}, {
y: 2,
color: colors[1],
}, {
y: 3,
color: colors[2],
},{
y: 5,
color: colors[3],
}];
function setChart(name, categories, data, color) {
chart.xAxis[0].setCategories(categories, false);
chart.series[0].remove(false);
chart.addSeries({
name: name,
data: data,
color: color || 'white'
}, false);
chart.redraw();
}
var chart = $('#review').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Review breakdown'
},
xAxis: {
categories: categories
},
tooltip: {
formatter: function() {
var point = this.point,
s = this.x +'<br><b>'+ this.y +' stars</b><br/>';
return s;
}
},
series: [{
name: name,
data: data,
color: 'white'
}],
exporting: {
enabled: false
},
legend: {
enabled: false
},
credits: {
enabled: false
}, yAxis: {min: 0, max: 5,
title: {text: 'Star Rating'}
}
})
.highcharts(); // return chart
});
$(function () {
var colors = Highcharts.getOptions().colors,
categories = ['positive', 'negative', 'sum'],
name = 'Votes',
data = [{
y: 55.11,
color: colors[0],
drilldown: {
name: 'Positive votes',
categories: ['Users', 'Admin', 'Anonymous'],
data: [10.85, 7.35, 33.06],
color: colors[0]
}
}, {
y: -7.15,
color: colors[3],
drilldown: {
name: 'Negative votes',
categories: ['Users', 'Admin', 'Anonymous'],
data: [-4.55, -1.42, -0.23],
color: colors[3]
}
}, {
y: 2.14,
color: colors[4],
drilldown: {
name: 'Total votes',
categories: ['Users', 'Admin', 'Anonymous'],
data: [ 0.12, 0.37, 1.65],
color: colors[4]
}
}];
function setChart(name, categories, data, color) {
chart.xAxis[0].setCategories(categories, false);
chart.series[0].remove(false);
chart.addSeries({
name: name,
data: data,
color: color || 'white'
}, false);
chart.redraw();
}
var chart = $('#votes').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Vote breakdown'
},
subtitle: {
text: 'Click the columns to view breakdown.'
},
xAxis: {
categories: categories
},
yAxis: {
title: {
text: 'Total votes'
}
},
plotOptions: {
column: {
cursor: 'pointer',
point: {
events: {
click: function() {
var drilldown = this.drilldown;
if (drilldown) { // drill down
setChart(drilldown.name, drilldown.categories, drilldown.data, drilldown.color);
} else { // restore
setChart(name, categories, data);
}
}
}
},
dataLabels: {
enabled: true,
color: colors[0],
style: {
fontWeight: 'bold'
}
}
}
},
tooltip: {
formatter: function() {
var point = this.point,
s = this.x +':<b>'+ this.y +' votes</b><br/>';
if (point.drilldown) {
s += 'Click to view '+ point.category +' breakdown';
} else {
s += 'Click to return';
}
return s;
}
},
series: [{
name: name,
data: data,
color: 'white'
}],
exporting: {
enabled: false
},
legend: {
enabled: false
},
credits: {
enabled: false
},
})
.highcharts(); // return chart
});
$(函数(){
var colors=Highcharts.getOptions().colors,
类别=[‘指标1’、‘指标2’、‘指标3’、‘指标4’],
名称='投票',
数据=[{
y:1,,
颜色:颜色[0],
}, {
y:2,
颜色:颜色[1],
}, {
y:3,
颜色:颜色[2],
},{
y:5,
颜色:颜色[3],
}];
功能设置图(名称、类别、数据、颜色){
chart.xAxis[0].setCategories(categories,false);
chart.series[0]。删除(false);
chart.addSeries({
姓名:姓名,,
数据:数据,
颜色:颜色| |“白色”
},假);
chart.redraw();
}
var图表=$(“#审查”)。高图表({
图表:{
类型:“列”
},
标题:{
文本:“回顾细分”
},
xAxis:{
类别:类别
},
工具提示:{
格式化程序:函数(){
var点=此点,
s=this.x+'
'+this.y+'stars
';
返回s;
}
},
系列:[{
姓名:姓名,,
数据:数据,
颜色:“白色”
}],
出口:{
已启用:false
},
图例:{
已启用:false
},
学分:{
已启用:false
},yAxis:{min:0,max:5,
标题:{text:'星级'}
}
})
.highcharts();//返回图表
});
$(函数(){
var colors=Highcharts.getOptions().colors,
类别=[“正”、“负”、“和”],
名称='投票',
数据=[{
y:55.11,
颜色:颜色[0],
向下展开:{
名称:“赞成票”,
类别:[“用户”、“管理员”、“匿名”],
数据:[10.85,7.35,33.06],
颜色:颜色[0]
}
}, {
y:-7.15,
颜色:颜色[3],
向下展开:{
姓名:'反对票',
类别:[“用户”、“管理员”、“匿名”],
数据:[-4.55,-1.42,-0.23],
颜色:颜色[3]
}
}, {
y:2.14,
颜色:颜色[4],
向下展开:{
姓名:'总票数',
类别:[“用户”、“管理员”、“匿名”],
数据:[0.12,0.37,1.65],
颜色:颜色[4]
}
}];
功能设置图(名称、类别、数据、颜色){
chart.xAxis[0].setCategories(categories,false);
chart.series[0]。删除(false);
chart.addSeries({
姓名:姓名,,
数据:数据,
颜色:颜色| |“白色”
},假);
chart.redraw();
}
var图表=$(“#投票”)。highcharts({
图表:{
类型:“列”
},
标题:{
文本:“投票分解”
},
副标题:{
文本:“单击列以查看明细。”
},
xAxis:{
类别:类别
},
亚克斯:{
标题:{
正文:“总票数”
}
},
打印选项:{
专栏:{
光标:“指针”,
要点:{
活动:{
单击:函数(){
var drilldown=this.drilldown;
如果(向下钻取){//向下钻取
集合图表(drilldown.name、drilldown.categories、drilldown.data、drilldown.color);
}否则{//restore
设置图(名称、类别、数据);
}
}
}
},
数据标签:{
启用:对,
颜色:颜色[0],
风格:{
fontWeight:“粗体”
}
}
}
},
工具提示:{
格式化程序:函数(){
var点=此点,
s=this.x+':'+this.y+'投票
';
if(点向下钻取){
s+='点击查看'+point.category+'细分';
}否则{
s+='点击返回';
}
返回s;
}
},
系列:[{
姓名:姓名,,
数据:数据,
颜色:“白色”
}],
出口:{
已启用:false
},
图例:{
已启用:false
},
学分:{
使可能
there's no relevant code to put here, just click the link