如何动态设置除 0 之外的 minPointLength

Nir*_*ath 2 javascript charts highcharts lazy-high-charts

我喜欢为高图表动态设置 minPointLengh 的值。但是下面提到的代码不起作用。你能帮我完成它吗?

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        xAxis: {
            categories: ['Sep', 'Oct', 'Nov', 'Dec']
        },

        plotOptions: {
        var minPointLength; 
                if(this.y > 0)  
                  minPointLength = 3,  
             else  
                  minPointLength = 0,
            series: {
                        minPointLength: minPointLength,
            }
        },
        series: [{
            data: [4, 0, 1, 5]
        }]
    });
});
Run Code Online (Sandbox Code Playgroud)

jlb*_*ggs 5

我的建议:将任何0值更改为null值。

minPointLength不会与空影响任何点y的值。

将代码更新为:

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        xAxis: {
            categories: ['Sep', 'Oct', 'Nov', 'Dec']
        },

        plotOptions: {
            series: {
              minPointLength: 3
          }
        },
        series: [{
            data: [4, null, 1, 5]
        }]
    });
});
Run Code Online (Sandbox Code Playgroud)

例子:

您的代码不起作用的另一个原因:您试图minPointLength直接在plotOptions对象内设置属性- 它需要在系列选择器对象之一(即“ series: {}”、“ column: {}”等)内。