动态更改Highcharts数据系列类型 [英] Changing Highcharts data series type dynamically

查看:143
本文介绍了动态更改Highcharts数据系列类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个系列的Highcharts,每个系列都选择".我的目的是通过选择"更改系列类型.

I have Highcharts with multiple series and 'select' for each series. My aim is to change series type via 'select'.

$('#ChType').change(function () {
    var series = chart.series[0]
    var newType = $('#ChType').val();
    changeType(series, newType);
})

$('#ChType2').change(function () {
    var series = chart.series[1]
    var newType = $('#ChType2').val();
    changeType(series, newType);
})

function changeType(series, newType) {
    var dataArray = [],
        points = series.data;
    series.chart.addSeries({
        type: newType,
        name: series.name,
        color: series.color,
        data: series.options.data
    }, false);
    alert(series.name);
    series.remove();
}

我知道,每次更改类型时,系列都会从数组中的当前位置中删除,并添加到末尾.目前,我只能更改位置系列[0]中的系列.

I understand that every time the type gets changed, series will get removed from it's current position in an array and added to the end. Currently I'm able to change only the series that is in the position series[0].

如何更改其他系列而不是仅更改系列[0]?

How can I change any other series and not just the series[0]?

我确实在此处看到了类似的问题,但无法完全正常工作.

I did see the similar question here but couldn't quite get it to work.

我在 jsFiddle 中的示例代码.

推荐答案

您可以使用v3.0 highcharts包含的series.update()方法,该方法允许动态更改图表的类型.

You can use v3.0 highcharts included series.update() method, which allows to change type of chart, dynamically.

http://jsfiddle.net/8Sg8K/1

chart.series[0].update({
                type: "column"
            });

这篇关于动态更改Highcharts数据系列类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆