highcharts - 2个日期选择器问题

时间:2017-02-11 04:43:33

标签: javascript highcharts

1)我想知道如何从图表的右侧删除日期选择器?我真的只需要左边的rangeSelector按钮,即24小时,6小时......

2)当你点击其中一个rangeSelector选项时,无论如何都要关闭dataLabels?

当放大显示5分钟的数据时,dataLabels很方便,但是当看24小时值时,由于拥挤,它们会使图表无法使用。如果在我缩小时可以自动关闭它们会很好。

非常感谢你的帮助,如果这确实可行的话。

对于第二个选项,我希望切换

的可见性
   plotOptions:{series: {
      dataLabels:{
            enabled:true, 

1 个答案:

答案 0 :(得分:0)

Fiddle Link

Highstock Example

自定义范围选择器后
/**
* Load new data depending on the selected min and max
 */
function afterSetExtremes(e) {

    var chart = Highcharts.charts[0];

    chart.showLoading('Loading data from server...');
    $.getJSON('https://www.highcharts.com/samples/data/from-sql.php?start=' + Math.round(e.min) +
            '&end=' + Math.round(e.max) + '&callback=?', function (data) {

        chart.series[0].setData(data);
        chart.hideLoading();
    });
}

// See source code from the JSONP handler at https://github.com/highcharts/highcharts/blob/master/samples/data/from-sql.php
$.getJSON('https://www.highcharts.com/samples/data/from-sql.php?callback=?', function (data) {

    // Add a null value for the end date
    data = [].concat(data, [[Date.UTC(2011, 9, 14, 19, 59), null, null, null, null]]);

    // create the chart
    Highcharts.stockChart('container', {
        chart: {
            type: 'candlestick',
            zoomType: 'x'
        },

        navigator: {
            adaptToUpdatedData: false,
            series: {
                data: data
            }
        },

        scrollbar: {
            liveRedraw: false
        },

        title: {
            text: 'AAPL history by the minute from 1998 to 2011'
        },

        subtitle: {
            text: 'Displaying 1.7 million data points in Highcharts Stock by async server loading'
        },

        rangeSelector: {
            buttons: [{     //customization of buttons
                type: 'hour',
                count: 24,
                text: '24h'
            }, {
                type: 'hour',
                count: 6,
                text: '6h'
            }, {
                type: 'minute',
                count: 5,
                text: '5m'
            }],
            inputEnabled: false, // it remove datepicker
        },

        xAxis: {
            events: {
                afterSetExtremes: afterSetExtremes,
                setExtremes: function(e) {
                    if(typeof(e.rangeSelectorButton)!== 'undefined')
                    {
                      if(e.rangeSelectorButton.text=='5m'){
                            addlables(); //function to add data label
                      }else{
                            removelables(); // function to remove data lable
                      }
                    }
                }
            },
            minRange: 300 * 1000 // 5min * 1000
        },

        yAxis: {
            floor: 0
        },
        plotOptions:{
        series: {
            dataLabels:{
            enabled:false,
            }
            }
        },

        series: [{
            data: data,
            dataGrouping: {
                enabled: false
            }
        }]
    });
});

function removelables(){
        var chart = $('#container').highcharts();
        var opt = chart.series[0].options;
        opt.dataLabels.enabled = false;
        chart.series[0].update(opt);
}
function addlables(){
        var chart = $('#container').highcharts();
        var opt = chart.series[0].options;
        opt.dataLabels.enabled = true;
        chart.series[0].update(opt);
}