简体   繁体   English

如何在高图中设置yaxis值

[英]how do you set the yaxis values in highcharts

my json data looks like this: 我的json数据如下所示:

[
 [1362027751000, 1362027781000, 1362027811000, 1362027841000, 1362027871000, 1362027901000, 1362027931000, 1362027961000, 1362027991000, 1362028021000 ],
[ 66, 72, 69, 72, 69, 68, 71, 73, 63, 57 ],
[ 50, 5, 67, 72, 34, 100, 10, 100, 23, 56 ] 

]

the first row is date in epoch time, the second is cpu utilization and the third is the memory utilization. 第一行是新纪元时间的日期,第二行是cpu利用率,第三行是内存利用率。 I would like to create time series chart, date being on xaxis and CPU and mmeory data on yaxis with different lines. 我想创建时间序列图,日期在xaxis上,CPU和mmeory数据在yaxis上,用不同的线表示。 How would I accomplish this given the data provided with the json external file. 给定json外部文件提供的数据,我将如何完成此任务。 I see examples where that the in the javascript but this is really not realistics. 我在javascript中看到了一些示例,但这实际上是不现实的。 Any help is greatly appriciated. 任何帮助都非常有用。

I attempted to the following where I wanted to split cpu and memory. 我尝试将以下内容拆分为CPU和内存。 I am not getting any results back, empty page. 我没有得到任何结果,空白页。 Is this the way to address this or there are other ways to draw multiple variables in one chart? 这是解决这个问题的方法,还是有其他方法可以在一张图表中绘制多个变量? my javascript looks like this: 我的JavaScript看起来像这样:

<script type="text/javascript">

        $(document).ready(function() {
                var options = {
                    chart: {
                        renderTo: 'container',
                        type: 'area'
                    },
                    xAxis: {
                        type: 'datetime'

                    },
                //series: [{}]
                series: [{{
                type: 'spline',
                name: 'CPU',
                data: cpu
            }, {
                type: 'spline',
                name: 'memory',
                data: memory
            }}]

                };

            $.getJSON('data.json', function(data) {
                options.series[0].data = data;
                var cpu = [];
                var memory=[];

                for(i=0; i< data.length, i++) {
                    for(j=0; j<data[i].length; j++){
                    alert(data[i].length);
                        cpu.push([
                            data[i][j], // the date
                            data[1][j] // the cpu

                        ]);
                        memory.push([
                            data[i][j], // the date
                            data[2][j] // the volume
                        ])
                    }
                }

                var chart = new Highcharts.Chart(options);
                //alert(JSON.stringify(data, null, 4));



            });

        });
     </script>  

the charts does not look right. 图表看起来不正确。 It looks like xaxis and yaxix are both reporting the date value. 看起来xaxis和yaxix都在报告日期值。 Is there a way to set the yaxis values? 有没有办法设置yaxis值?

My preference is to send in the data for a series as [x,y] pairs. 我的偏好是以[x,y]对的形式发送数据。 So your data would look like: 因此您的数据如下所示:

[
[1362027751000, 66], [1362027781000, 72], [1362027811000, 69], [1362027841000, 72], [1362027871000, 69], [1362027901000, 68], [1362027931000, 71], [1362027961000, 73], [1362027991000, 63], [1362028021000, 57 ]
]

and: 和:

[
[1362027751000, 50], [1362027781000, 5], [1362027811000, 67], [1362027841000, 72], [1362027871000, 34], [1362027901000, 100], [1362027931000, 10], [1362027961000, 100], [1362027991000, 23], [1362028021000, 23]
]

You would need to send this in as 2 different series.data blocks. 您需要将其作为2个不同的series.data块发送。

   for(i=0; i< data.length-2; i++) {
          for(j=0; j<data[i].length; j++){

               cpu.push([
    data[i][j], // the date
    data[1][j] // the cpu

     ]);
     memory.push([
    data[i][j], // the date
    data[2][j] // the volume
     ])
}
  }

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

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