在更改Highcharts中的图表类型时修复/折扣数据系列 [英] Fixing/discounting a data series when changing chart-type in Highcharts
问题描述
我使用高图来显示两个系列的数据。第一个是主要数据,第二个是根据初始数据计算的趋势线。麻烦的是,当更改图表类型时,它将趋势线计数为相同的系列,并与第一个一起进行堆叠/绘制。
我试图:b
$ b
- 保留趋势线数据为虚线类型并仅更改主数据图表键入
- 或 - - 删除/折扣趋势线,如果无法保持原样。
我把精确的问题放在jsfiddle 这里。
HTML下拉菜单:
< select id =chartType>
< option value =spline> Spline< / option>
< option value =line> Line< / option>
< option value =column>列< / option>
< option value =area> Area< / option>
< / select>
我用来更改图表类型的功能:
$('#chartType')。change(function(){
changeType(chart.series,this.value) ;
});
函数changeType(series,newType){
serie = series [0];
serie.chart.addSeries({
类型:newType,
名称:serie.name,
颜色:serie.color,
数据:serie.options.data
},false);
serie.remove();
chart.redraw();
}
我已经使用 series [0]
作为我函数中的主要数据 - 因为它是第一个要加载的系列,但是当我随机循环下拉选项时,它似乎几乎循环了这个系列 - 更改趋势线的图表类型...几乎好像在更改类型后更新的系列顺序交换!
任何想法/黑客/解决方案?
系列数据:
系列:[
{
lineWidth:6,
name:'Primary data',
data:[59.359,60.395,68.830,70.290,73.259,81.344,60.113,60.113, 80.644,110.929,96.731,78.104]
},
{
lineWidth:3,
dashStyle:'dash',
名称:'Trend-line',
颜色:'#999999',
阴影:0,
数据:[59.259,62.123,64.986,67.850,70.714,73.577,76.441,79.305,82.168,85.032,87.896,90.759]
是你每次看系列[0]。但是,因为您每次都删除趋势线,然后添加一个新的趋势线,所以系列[0]每次都会更改。因此,您需要做的是增加一种感觉一致性,如下所示:
for(i = 0; i< series.length; i ++){
if (系列[i] .name =='主数据'){
serie = series [i];
}
}
// serie = series [0];
I'm using highcharts to display two series of data. The first is the primary data, the second is a calculated trend-line based upon the initial data. The trouble is, when changing the chart-type it's counting the trend-line as an equal series and stacking/drawing it along with the first.
I'm trying to either:
- Leave the trend-line data as a dashed-line type and changing ONLY the primary data chart type
--or-- - Remove/discount the trend-line, if it's not possible to leave it as is.
I've put the exact problem on jsfiddle here.
The HTML dropdown:
<select id="chartType">
<option value="spline">Spline</option>
<option value="line">Line</option>
<option value="column">Column</option>
<option value="area">Area</option>
</select>
The function I'm using to change the chart type:
$('#chartType').change(function(){
changeType(chart.series, this.value);
});
function changeType(series, newType) {
serie = series[0];
serie.chart.addSeries({
type: newType,
name: serie.name,
color: serie.color,
data: serie.options.data
}, false);
serie.remove();
chart.redraw();
}
I've used series[0]
as the primary data in my function - as it's the first series to be loaded, but when I randomly cycle through the dropdown options, it seems to almost cycle the series - changing the chart-type of the trend-line... It's almost as though the updated series order swaps after changing type!
Any ideas/hacks/solutions?
The series data:
series: [
{
lineWidth: 6,
name: 'Primary data',
data: [59.359,60.395,68.830,70.290,73.259,81.344,60.113,60.113,80.644,110.929,96.731,78.104]
},
{
lineWidth: 3,
dashStyle: 'dash',
name: 'Trend-line',
color: '#999999',
shadow: 0,
data: [59.259,62.123,64.986,67.850,70.714,73.577,76.441,79.305,82.168,85.032,87.896,90.759]
}
]
What's happening is that you are looking at series[0] each time. But because you are removing a trendline and then adding a new one each time, series[0] changes each time.
So what you need to do is add a sense of consistency, like so:
for ( i = 0 ; i < series.length ; i++ ) {
if ( series[i].name == 'Primary data' ) {
serie = series[i];
}
}
// serie = series[0];
这篇关于在更改Highcharts中的图表类型时修复/折扣数据系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!