简体   繁体   English

高图分散了外部数据

[英]Highcharts scatter external data

I created document with highcharts scatter graph 我用highcharts散点图创建了文档

                Highcharts.chart('container', {
                chart: {
                    type: 'scatter',
                    zoomType: 'xy'
                },
                title: {
                    text: ''
                },
                subtitle: {
                    text: ''
                },
                xAxis: {
                    title: {
                        enabled: true,
                        text: 'Date of entry'
                    },
                    startOnTick: true,
                    endOnTick: true,
                    showLastLabel: true
                },
                yAxis: {
                    title: {
                        text: 'Values'
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'left',
                    verticalAlign: 'top',
                    x: 100,
                    y: 70,
                    floating: true,
                    backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',
                    borderWidth: 1
                },
                plotOptions: {
                    scatter: {
                        marker: {
                            radius: 5,
                            states: {
                                hover: {
                                    enabled: true,
                                    lineColor: 'rgb(100,100,100)'
                                }
                            }
                        },
                        states: {
                            hover: {
                                marker: {
                                    enabled: false
                                }
                            }
                        },
                        tooltip: {
                            headerFormat: '<b>{series.name}</b><br>',
                            pointFormat: 'Dana {point.x} = {point.y}'
                        }
                    }
                },
                series: [{
                    name: 'Values',
                    color: 'rgba(223, 83, 83, .5)',
                    data: [[167.6, 64.5], [167.6, 72.3], [167.6, 61.4]]
                }]
            });

and this works. 这可行。 This code is from documentation page. 此代码来自文档页面。 I get normal scatter data like on this page Highcharts scatter jsfiddle Now, I created another PHP file that produces me with data I actually need. 我得到了正常的散点数据,例如此页面上的Highcharts散点jsfiddle现在,我创建了另一个PHP文件,该文件使用实际需要的数据生成我。 it is in document highcharts.php and result is this 它在文件highcharts.php中,结果是这个

[07.03.2017,21000],[07.03.2017,25000],[07.03.2017,33000],[07.03.2017,27000],[07.03.2017,30000],[01.01.2017,700],[11.05.2017,0],[11.05.2017,0],[11.05.2017,0],[11.05.2017,0], [07.03.2017,21000],[07.03.2017,25000],[07.03.2017,33000],[07.03.2017,27000],[07.03.2017,30000],[01.01.2017,700],[11.05 .2017,0],[11.05.2017,0],[11.05.2017,0],[11.05.2017,0]

how to connect data to this highcharts.php file? 如何将数据连接到此highcharts.php文件? I found some examples but I cannot get it to work. 我找到了一些示例,但无法使其正常工作。 So for start I need this, ONE line of data to show on scatter diagram. 因此,一开始我需要这一点,在散点图上显示一行数据。 I lost few days and just do not get it what I am doing wrong. 我失去了几天,只是不明白我做错了什么。

If your PHP file returns the array presented above, you need to parse it a little bit in order to use it as data array in a scatter series. 如果您的PHP文件返回上面显示的数组,则需要对其进行一些解析,以便将其用作分散系列中的数据数组。 First of all, dates should be strings. 首先,日期应该是字符串。 Secondly, you need to use new Date() to create Date instance and use getTime() to return timestamps. 其次,您需要使用new Date()创建Date实例,并使用getTime()返回时间戳。 Also, change xAxis type to datetime . 另外,将xAxis类型更改为datetime

API Reference: API参考:
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime

Example: 例:
http://jsfiddle.net/0025rsmt/ http://jsfiddle.net/0025rsmt/

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

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