我有一个x范围高图,用于显示事件时间线。我能够使它适用于具有开始和结束日期的事件。但是我有尚未结束的事件,对于这些事件,我需要扩展图表的数据点而不停止,如下所示。绿色活动尚未结束。

javascript - Highchart x范围图扩展了数据点而没有结束-LMLPHP

以下是我现有的代码:



Highcharts.chart('container', {
    chart: {
        type: 'xrange',
        height: 100
    },
    title: {
        text: ''
    },
    xAxis: {
        visible: true,
        tickLength: 0,
        lineWidth: 6,
        lineColor: '#000',
        labels: {
            enabled: false
        }
    },
    yAxis: {
        visible: false
    },
    legend: {
        enabled: false
    },
    series: [{
        name: '',
        borderRadius: 0,
        pointPadding: 0,
        borderWidth: 6,
        groupPadding: 0,
        data: [{
            x: Date.UTC(2014, 10, 21),
            x2: Date.UTC(2014, 11, 2),
            y: 0,
            color: 'transparent',
            borderColor: 'rgba(230, 141, 11, 0.5)'
        }, {
            x: Date.UTC(2014, 10, 26),
            x2: Date.UTC(2014, 11, 5),
            y: 0,
            color: 'transparent',
            borderColor: 'rgba(228, 53, 70, 0.5)'
        }, {
            x: Date.UTC(2014, 11, 8),
            x2: Date.UTC(2014, 11, 10),
            y: 0,
            color: 'transparent',
            borderColor: 'rgba(40, 167, 69, 0.5)'
        }, {
            x: Date.UTC(2014, 11, 9),
            x2: Date.UTC(2014, 11, 12),
            y: 0,
            color: 'transparent',
            borderColor: 'rgba(40, 147, 164, 0.5)'
        }],
        dataLabels: {
            enabled: false
        }
    }]

});

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/xrange.js"></script>

<div id="container"></div>





我尝试将Date.UTC(0, 0, 0)放在x2上,但是没有按预期工作。 Highcharts中的xrange图表是否可以做到这一点?提前致谢!

最佳答案

您可以将x2值设置为晚于xAxis.max的日期:

xAxis: {
    ...,
    max: Date.UTC(2014, 11, 5)
},
...,
series: [{
    data: [{
        x: Date.UTC(2014, 10, 26),
        x2: Date.UTC(2014, 11, 15),
        ...
    }],
    ...
}]


现场演示:http://jsfiddle.net/BlackLabel/9f6Lejbs/

API参考:https://api.highcharts.com/highcharts/xAxis.max

09-26 22:13
查看更多