如何在海图时间轴中设置每个点的不同距离?

时间:2019-10-05 17:06:09

标签: javascript highcharts timeline

我看到Highchart的timeline chart自定义了每个点dataLabel
我想添加dataLabel选项为每个点(数据)设置不同的distance。所以我添加了如下代码所示的选项。

但是当我使用此代码时,看来distance选项无法正常工作。 dataLabel's的所有距离都相同。

我该如何解决?我用错了吗?

Highcharts.chart('container', {
    chart: {
        type: 'timeline'
    },
    series: [{
        data: [{
            date: 'Some date',
            label: 'Event label',
            description: 'Description of this event.',
            dataLabels: {
                color: '#78f',
                borderColor: 'blue',
                backgroundColor: '#444',
                connectorWidth: 2,
                connectorColor: 'blue',
                distance : 80, // I add this option for different distance
                style: {
                    textOutline: 0
                }
            }
        },{
            date: 'Another date',
            label: 'Last event label',
            description: 'Description of third event.',
            dataLabels :{
                 distance : 20
           }
        }]
    }]
});

1 个答案:

答案 0 :(得分:0)

您可以使用distance属性来代替为所有数据标签设置的y

series: [{
    data: [{
        ...,
        dataLabels: {
            y: -50,
            ...
        }
    }, {
        ...,
        dataLabels: {
            y: 120
        }
    }]
}]

实时演示: http://jsfiddle.net/BlackLabel/femo49gn/

API参考: https://api.highcharts.com/highcharts/series.timeline.dataLabels.y