簡體   English   中英

動態更新工具提示日期格式的圖表

[英]Dynamically update tooltip date format highchart

我想動態更新工具提示日期格式。 像按鈕單擊事件一樣,工具提示日期格式將更改為另一種格式。 看看我的HTML:

<div id="container" style="height: 300px"></div>
<button id="dateFormate">changeDateFormat</button>
on Click the button date format chang to %m-%d-%y 

使用Javascript

$(function () {
$('#container').highcharts({

    xAxis: {
        type: 'datetime'
    },

    tooltip: {
        xDateFormat: '%Y-%m-%d',
        shared: true
    },

    plotOptions: {
        series: {
            pointStart: Date.UTC(2012, 0, 1),
            pointInterval: 24 * 3600 * 1000
        }
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }, {
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4].reverse()
    }]

});

});

http://jsfiddle.net/hL8ae0yr/

您還可以在系列中定義工具提示格式,然后使用新格式更新系列數組。

示例: http//jsfiddle.net/hL8ae0yr/1/

chart.series[0].update({
            tooltip:{
                xDateFormat: '%Y/%m/%d',
            }
});

這可以通過重建圖表來完成。 繪制圖表后,我無法找到一種方法來重置chart.tooltip.options。 因此,您可以執行以下操作:

$("#dateFormate").click(function () {
    var theChart = $('#container').highcharts();
    var initOptions = theChart.options;
    var options0 = {
        tooltip: {
            xDateFormat: '%m-%d-%y'
        }
    };

    optionsNew = Highcharts.merge(initOptions, options0);

    $('#container').highcharts(optionsNew);
});

tooltip.xDateFormat新的tooltip.xDateFormat與現有的圖表選項合並,然后重新創建圖表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM