Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示来自php和mysql的每周Highcharts图_Php_Mysql_Highcharts - Fatal编程技术网

显示来自php和mysql的每周Highcharts图

显示来自php和mysql的每周Highcharts图,php,mysql,highcharts,Php,Mysql,Highcharts,我正在尝试使用Highcharts显示图表。我使用php从mysql数据库中提取数据,创建数据数组并将其插入Highcharts Jquery 我需要以这种格式显示数据(不是图形表示): 周一总是第一个,周日总是最后一个 但我的数据是使用日期范围从数据库中提取的,我可能只能从数据库中获取如下所示的数组: Array ( [0] => Array ( [TotalClicksPerDay] => 35 [weekD

我正在尝试使用Highcharts显示图表。我使用php从mysql数据库中提取数据,创建数据数组并将其插入Highcharts Jquery

我需要以这种格式显示数据(不是图形表示):

周一总是第一个,周日总是最后一个

但我的数据是使用日期范围从数据库中提取的,我可能只能从数据库中获取如下所示的数组:

Array
(
    [0] => Array
        (
            [TotalClicksPerDay] => 35
            [weekDay] => 4 (which is my case is Thurs)
        )
}
因此,在这种情况下,需要显示: (TotalClicksPerDay是重要的一位)

我如何将数组值添加到Highchart中,并且仍然获得一周中的天数来显示“thu”值并将其放置在正确的位置

有人做过类似的事吗?你能给我指一下正确的方向吗? 我甚至不知道如何开始

下面是我的highcharts Jquery,您可以看到我是如何使用数组的:

    jQuery(document).ready(function($) {
          var chart;
            $(document).ready(function() {
              chart = new Highcharts.Chart({
                chart: {
                  renderTo: 'container',
                  type: 'column'
                },
                title: {
                  text: '$type'
                },


   subtitle: {
              text: 'Xbox landscape'
            },
            xAxis: {
              categories: 
              $categoryGraph //php array
              ,labels: {
              rotation: 0,
                align: 'center',
                x: 0,
                y: 20,
                style: {
                  fontSize: '8px',
                  fontFamily: 'Verdana, sans-serif'
                }
              }
            },
            yAxis: {
              min: 0,
              title: {
                text: 'Clicks'
              }
            },
            legend:  {
                    enabled: false
                }, /*{
              layout: 'Vertical',
                backgroundColor: '#FFFFFF',
                align: 'left',
                verticalAlign: 'top',
                x: 0,
                y: 30,
                floating: false,
                shadow: true
              },*/
             tooltip: {
                formatter: function() {
                  return ''+
                    this.x +': '+ this.y +' Clicks';
                  }
              },
              plotOptions: {
                column: {
                  pointPadding: 0.2,
                    borderWidth: 0
                }
              },
              series: [{name: '$type', data:[$clickTotalArray //php array }]
            });
        });
    });

您正在询问如何将数据解析为highcharts能够理解的内容

好的,您要正确设置的主要动态选项是
xAxis.categories
series.data
,您似乎已经找到了它们

类别
需要是一个字符串数组,不接受多或少

例如:-
categories=['Mon','Tue','Wed']

数据
需要是数组或对象数组或值数组

由于数据大多是简单的值,xValue是一个字符串,因此属于类别,因此
数据
对象需要是一个数字数组

例如:-
data=[100200300]

现在我们有了数据的最终形式,我们需要将可用的数据结构/对象图解析为这种形式。您可以选择在PHP或JavaScript中执行此操作

这就是如何在javascript中执行此操作的方法,请确保在调用
Highchart
构造函数之前执行此操作,并在设置选项时使用派生对象

var superData = [{
    propertyA: 'A',
    propertyB: 10
}, {
    propertyA: 'B',
    propertyB: 15
}, {
    propertyA: 'C',
    propertyB: 1
}];

var seriesData = [],
    categories = [];
for (var i = 0; i < superData.length; i++) {
    //you may want to do a parseInt/parseFloat it this value is a string
    seriesData.push(superData[i].propertyB);
    categories.push(superData[i].propertyA);
}

...
    xAxis: {
        categories: categories
    },
    series: [{
        name: 'serie',
        type: 'column',
        data: seriesData
        }]
...
var superData=[{
房地产:A,
物业b:10
}, {
物业A:‘B’,
物业b:15
}, {
物业A:‘C’,
物业b:1
}];
var seriesData=[],
类别=[];
对于(var i=0;i

请参阅了解如何在PHP中完成类似的操作

    jQuery(document).ready(function($) {
          var chart;
            $(document).ready(function() {
              chart = new Highcharts.Chart({
                chart: {
                  renderTo: 'container',
                  type: 'column'
                },
                title: {
                  text: '$type'
                },


   subtitle: {
              text: 'Xbox landscape'
            },
            xAxis: {
              categories: 
              $categoryGraph //php array
              ,labels: {
              rotation: 0,
                align: 'center',
                x: 0,
                y: 20,
                style: {
                  fontSize: '8px',
                  fontFamily: 'Verdana, sans-serif'
                }
              }
            },
            yAxis: {
              min: 0,
              title: {
                text: 'Clicks'
              }
            },
            legend:  {
                    enabled: false
                }, /*{
              layout: 'Vertical',
                backgroundColor: '#FFFFFF',
                align: 'left',
                verticalAlign: 'top',
                x: 0,
                y: 30,
                floating: false,
                shadow: true
              },*/
             tooltip: {
                formatter: function() {
                  return ''+
                    this.x +': '+ this.y +' Clicks';
                  }
              },
              plotOptions: {
                column: {
                  pointPadding: 0.2,
                    borderWidth: 0
                }
              },
              series: [{name: '$type', data:[$clickTotalArray //php array }]
            });
        });
    });
var superData = [{
    propertyA: 'A',
    propertyB: 10
}, {
    propertyA: 'B',
    propertyB: 15
}, {
    propertyA: 'C',
    propertyB: 1
}];

var seriesData = [],
    categories = [];
for (var i = 0; i < superData.length; i++) {
    //you may want to do a parseInt/parseFloat it this value is a string
    seriesData.push(superData[i].propertyB);
    categories.push(superData[i].propertyA);
}

...
    xAxis: {
        categories: categories
    },
    series: [{
        name: 'serie',
        type: 'column',
        data: seriesData
        }]
...