我想为高位图表创建动态数据,
我需要在 x 轴上生成动态值
xAxis: {
categories:['project1','project2']
},
这是我的for循环,
var project = [];
for(var i=0;i<project.name;i++){
//new array
}
如何在 x 轴上创建动态值。
我想为高位图表创建动态数据,
我需要在 x 轴上生成动态值
xAxis: {
categories:['project1','project2']
},
这是我的for循环,
var project = [];
for(var i=0;i<project.name;i++){
//new array
}
如何在 x 轴上创建动态值。
您可以将数组变量作为参数传递给图表的类别选项。
例子:
// Original array
var categories1=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
// Copy and/or modifify the second array content and do some stuff
var categories2=[];
for(var i=0;i<categories1.length;i++){
categories2.push(categories1[i]);
}
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
xAxis: {
categories: categories2 // reference categories to an array variabile
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
工作小提琴:http: //jsfiddle.net/IrvinDominin/6c8Af/
我正在使用 JSON 数据,经过很长时间能够解决它。我的要求是获取 JSON 数据,然后根据我的数据要求创建一个地图对象。并动态创建图表系列。我能够创建系列,但图表中没有任何内容。
这是因为必须将数字转换为 Int 。当我使用 parseInt 时,它对我有用。
第 1 步:我得到 JSON 数据,操作后它看起来像这样:seriesData = {"O":series1}, {"A":Series2}, {"S":Series3}]
var options = {
chart: {
renderTo: 'demoGraph',
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: [1, 2, 3, 4, 5,6],
title: {
text: 'Severity'
},
},
yAxis: {
min: 0,
title: {
text: 'Total Defects with Severity - 1,2,3,4,5,6'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -70,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function () {
return '<b>' + this.x + '</b><br/>' +
this.series.name + ': ' + this.y + '<br/>' +
'Total: ' + this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black, 0 0 3px black'
}
}
}
},
series: [{},{},{},{},{},{}],
};
for(var i in seriesData ){
for(var j in seriesData [i]){
options.series[i].name = j;
options.series[i].data = seriesData [i][j];
break;
}
}
var chart = new Highcharts.Chart(options);
另一种方法:
var Series2 = [1,1,1,2,2,2];
var names=['O','A'];
var data1=Series2,seriesArray; //seriesArray is formed dynamically - array of int values
options.series = [{name: names, data: data1}]
这工作正常