简体   繁体   English

日期未正确显示在高库存图表的x轴上

[英]Date not displaying correctly on x-axis in High Stock Charts

I am working on stock charts where i have to show the stock data of three currencies. 我正在绘制股票图表,其中必须显示三种货币的股票数据。 I am able to see the chart and rates corresponding to it but dates on x axis are not coming properly. 我可以看到图表和与其对应的汇率,但是x轴上的日期显示不正确。 my json response is like this . 我的json响应是这样的。

[{"rate":1.3349,"month":"1422403200000"},{"rate":1.3415,"month":"1422316800000"},{"rate":1.3394,"month":"1422230400000"},{"rate":1.3202,"month":"1421971200000"},{"rate":1.304,"month":"1421884800000"},{"rate":1.3109,"month":"1421798400000"},{"rate":1.3017,"month":"1421712000000"},{"rate":1.3114,"month":"1421625600000"},{"rate":1.305,"month":"1421366400000"},{"rate":1.292,"month":"1421280000000"},{"rate":1.2876,"month":"1421193600000"},{"rate":1.2819,"month":"1421107200000"},{"rate":1.2801,"month":"1421020800000"}]

its just an example of json response. 它只是json响应的一个例子。 in my java vo rate is of double type and month is of String type. 在我的Java vo中,rate是double类型,month是String类型。

my js code is here 我的js代码在这里

function drawChart(){

    var seriesOptions = [],
        seriesCounter = 0,
        names = ['EURGBP', 'EURJPY', 'EURCHF'],
        // create the chart when all data is loaded
        createChart = function () {

            $('#drawchart').highcharts('StockChart', {

                rangeSelector: {
                    selected: 4
                },

                yAxis: {
                    labels: {
                        formatter: function () {
                            return (this.value > 0 ? ' + ' : '') + this.value + '%';
                        }
                    },
                    plotLines: [{
                        value: 0,
                        width: 2,
                        color: 'silver'
                    }]
                },

                plotOptions: {
                    series: {
                        compare: 'percent'
                    }
                },

                tooltip: {
                    pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
                    valueDecimals: 2
                },

                series: seriesOptions
            });
        };

    $.each(names, function (i, name) {

        $.getJSON('/bin/drawChart,    function (data) {
            var dataArray = new Array;
 $.each(data, function (i, obj) {
   dataArray.push([obj.month,obj.rate]);
  });
            alert(dataArray);
            seriesOptions[i] = {
                name: name,
                data: dataArray,
                 tooltip: {
                    valueDecimals: 2
              }
            };

            // As we're loading the data asynchronously, we don't know what order it will arrive. So
            // we keep a counter and create the chart when all the data is loaded.
            seriesCounter += 1;

            if (seriesCounter === names.length) {
                createChart();
            }
        });
    });

}

Why date is not appearing correctly on x-axis 为什么日期无法在X轴上正确显示

The problem is that in your JSON should be fields x and y. 问题是在您的JSON中应该是字段x和y。 Morever values should be number not string as you have. 而且,值应该是数字而不是字符串。 So you should prepare correct JSON structure in your backend or parse it after loading. 因此,您应该在后端准备正确的JSON结构,或者在加载后解析它。

绘制图表方法中缺少您的X轴信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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