首页 > 解决方案 > 在比较多个系列 highstock 中更改 yAxis 值以显示点值而不是百分比变化值

问题描述

嗨,我正在使用 Highstock 图表比较

    Highcharts.stockChart('container', {

        rangeSelector: {
            selected: 4
        },

        yAxis: {
            labels: {
                formatter: function () {
                    return (this.value > 0 ? ' + ' : '') + this.value + '%';
                }
            },
            plotLines: [{
                value: 0,
                width: 2,
                color: 'silver'
            }]
        },

        plotOptions: {
            series: {
                compare: 'percent',
                showInNavigator: true
            }
        },

        tooltip: {
            pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
            valueDecimals: 2,
            split: true
        },

        series: seriesOptions
    });
}

在此处输入图像描述

point.y正如我们所看到的, y轴的值是 0%、20%、40%,我们是否可以point.changeyAxis.

要求是显示实际值而不是百分比变化yAxis

labels: {
            formatter: function () {
                return (this.value > 0 ? ' + ' : '') + this.value + '%';
            }
        },

我认为目前this.value在 yAxis 标签是百分比变化point.change,我们可以显示代表的值point.y

这可能吗

注意 y 轴值不应硬编码

标签: javascripthighcharts

解决方案


改变series这样的:

plotOptions: {
  series: {
    //compare: 'percent',
    compare: 'value',
    showInNavigator: true
  }
},

小提琴


推荐阅读