$。每个只显示一个系列的高图 [英] $.each only shows one series highcharts
问题描述
关注这个问题: php-json-highcharts-load-database-result 答案是按照 这可以使用饼图,如果我更改为另一种类型( 我该如何做这项工作?在highchart文档中,如果该系列文件带有 这是因为饼图和折线图有不同的格式series.data。 折线图的series.data示例: Focusing in this question: php-json-highcharts-load-database-result The answer was to do the follow This works using pie charts, and if I change to another type ( How can I make this work? In the highchart docs, if the series came with
It happens because pie and line chart have different format of series.data.
Example of series.data for pie chart: Example of series.data for line chart:
这篇关于$。每个只显示一个系列的高图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
每个
:
$。getJSON('ajax / calc.ajax.php',function(data){
var series = {//< ----- ---------------创建一个系列对象
类型:'pie',
data:[] //新系列的数据数组
} ;
$ .each(data,function(key,value){
series.data.push([key,value [0]]);
});
options .series.push(series); //< --------推送系列对象
var chart = new Highcharts.Chart(options);
});
line例如
),相同的 $。每个
都会完成工作,除了显示多个系列。我已经尝试了将这个系列放入每个系列中,但都没有成功。
name
,则该名称将显示为系列。像这样:
{
类型:'bar',
名称:'Apple'//显示只有一次
data:[]
};
饼图的series.data示例:
系列:[{
type:'pie' ,
名称:'浏览器共享',
数据:[
['Firefox',45.0],
['IE',26.8],
{
name:'Chrome',
y:12.8,
切片:true,
选中:true
},
['Safari',8.5],
['Opera',6.2],
['Others',0.7]
]
}]
系列:[{
名称:'东京',
数据:[7.0,6.9,9.5,14.5,18.2,21.5,25.2,26.5,23.3,18.3,13.9,9.6]
},{
名称:'纽约',
数据:[-0.2,0.8,5.7,11.3,17.0,22.0,24.8,24.1,20.1,14.1,8.6,2.5]
},{
名称:'柏林',
数据:[-0.9,0.6,3.5,8.4, 13.5,17.0,18.6,17.9,14.3,9.0,3.9,1.0]
},{
名称:'伦敦',
数据:[3.9,4.2,5.7,8.5,11.9, 15.2,17.0,16.6,14.2,10.3,6.6,4.8]
}]
each
:$.getJSON('ajax/calc.ajax.php', function(data) {
var series = { // <-------------------- create just one series object
type: 'pie',
data: [] //data array for new series
};
$.each(data, function(key, value) {
series.data.push([key, value[0]]);
});
options.series.push(series); // <-------- pushing series object
var chart = new Highcharts.Chart(options);
});
line
for example), the same $.each
will do the work except showing more then one series. I've already tryied putting the series inside the each, but without success.name
, the name will appear as series. like this: {
type: 'bar',
name: 'Apple' // showing only once
data: []
};
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
series: [{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]