javascript Highcharts:如何重命名系列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7295092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 23:38:09  来源:igfitidea点击:

Highcharts: How to rename series

javascriptrenamehighchartsseries

提问by Chris

I'm using highcharts in my web application and I was wondering if there's any way to rename a series after the chart hast been created??

我在我的 Web 应用程序中使用 highcharts,我想知道在图表创建后是否有任何方法可以重命名系列?

Thanks in advance!!

提前致谢!!

采纳答案by eolsson

There is no method for doing this in the API. You could remove the series and add it again with another name, but that will make the animations run a second time and I think it will be colored with a new color as well.

API 中没有执行此操作的方法。您可以删除该系列并使用另一个名称再次添加它,但这将使动画第二次运行,我认为它也将使用新颜色进行着色。

回答by buaacss

actually, there's a way now. In highchars 3.0 series added a new api, called update:

实际上,现在有办法了。在 highchars 3.0 系列中添加了一个新的 api,称为 update:

chart.series[0].update({name:"name u want to change"}, false);
chart.redraw();

it will not only update the series name below the chart, but the name in tooltip as well.

它不仅会更新图表下方的系列名称,还会更新工具提示中的名称。

Cheers!

干杯!

回答by Lukas

This seems to work :

这似乎有效:

chart.series[1].name="Renamed";
chart.redraw();

回答by jAntoni

It is not required to Redraw chart again We can include it along with the series option in the Chart declaration as below:

不需要再次重绘图表我们可以将其与系列选项一起包含在图表声明中,如下所示:

        var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'high_container'
        },title: {
            text: 'IO Signal  Data'
        },subtitle: {
            text: 'Source: GPS Modem'
        },

        yAxis: {
            title: {
                text: 'Value'
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle'
        },


        xAxis: {
            type: 'datetime',
            labels: {
                enabled: true,
                formatter: function () { return ddd[this.value][0]; }, //<=== the value to plot chart

            }
        },
        series: [{
            data: ddd,
            name: SeriesName
        }]
    });