简体   繁体   中英

Highstock data not showing when setting xAxis min and max

I'm not able to set the xAxis min and max without screwing with the data. I tried using plotOptions and setting pointStart: Date.UTC(2016, 3, 1) but doing that screws with the data. The series ends up on the far right and doesn't load properly.

Is it possible to set a min and a max and make the data obey whatever is set? It loads properly when I don't set min and max . I need it to start in April 2016 and end on April 2018 with a tick every month.

Fiddle: https://jsfiddle.net/omaraziz/h5jsk7a3/5/

Here is an almost working version that just needs the xAxis dates and the tick (data is not exactly the same, but the same exact setting of the json:

在此处输入图片说明

The data is coming from a JSON file (data.json):

{
   "(1)": [1,2,3,4,5],
   "(2)": [6,7,8,9,0]
   "(3)": [1,4,7,2,0]
}

Setting the options:

var myChart = function() drawChart() {
     $("#container").highcharts("StockChart", {

            rangeSelector: {
                 enabled: false
            },

            xAxis: {
                 type: 'datetime',
                 tickInterval: (24 * 3600 * 1000) * 30, // every month
                 min: Date.UTC(2016, 3, 1),
                 max: Date.UTC(2018, 3, 4)
            },

           series: processedData, // from the data loaded below

    });

};

Loading JSON:

processedData = [];

$(function () {
    $getJSON("data.json", function(data) {

        for(let value in data) {

            if(data.hasOwnProperty(value)) {
                processedData.push({
                   name: value,
                   data: data[value],
                })

        }
        myChart(); // after the data has loaded
   });
});

If Your are recording your data at each hour, I hope your problem would be solved by using these two lines of code:

pointStart:Date.UTC(2016, 3, 1),
pointInterval: 3600 * 1000

Here is example:

 var myChart = function drawChart() { $("#container").highcharts("StockChart", { rangeSelector: { enabled: false, }, xAxis: { type: 'datetime', ordinal: false, min: Date.UTC(2016, 3, 1), max: Date.UTC(2018, 3, 4) }, plotOptions:{ series:{ pointStart:Date.UTC(2016, 3, 1), pointInterval: 3600 * 1000 } }, series: processedData, }); }; const processedData = []; $(function () { $.getJSON("https://omaraziz.me/CC-chart/new-activity.json", function (data) { for(let value in data) { if(data.hasOwnProperty(value)) { processedData.push({ //pointStart: Date.UTC(2016, 3, 1), name: value, data: data[value], }) } } myChart(); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.highcharts.com/stock/highstock.src.js"></script> <div id="container"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM