想要在高清工具提示中获取mysql字段记录

时间:2015-09-01 09:54:29

标签: javascript json codeigniter highcharts

这里我使用带有codeigniter的高图。我得到了图表的高图记录,但我希望记录来自" zreadactivity"的mysql数据库字段。在工具提示中。我无法在工具提示中获得" zreadactivity"因为它包含记录。所以,我只是想知道我被困在哪里? 这是我的代码: 控制器:

public function branchwiseactivityavg()
    {
        $data = $this->Data->branch_wise_activities();

        $category = array();
        $category['name'] = 'EndDate'; 

        $series1 = array();
        $series1['name'] = 'TotalValue';

        $series2 = array();
        $series2['name'] = 'zreadactivity';

        foreach ($data as $row)
        {
            $category['data'][] = $row->EndDate;
            $series1['data'][] = $row->TotalValue;
            $series2['data'][] = $row->zreadactivity;
        }
        $result = array();
        array_push($result,$category);
        array_push($result,$series1);
        array_push($result,$series2);


        print json_encode($result, JSON_NUMERIC_CHECK);
    }

使用Javascript:

<script type="text/javascript">
      $(document).ready(function() { 
            var options = { 
                chart: {
                    renderTo: 'container5',
                    type: 'column',
                    marginRight: 130,
                    marginBottom: 25,
                        zoomType: 'x'
                },
                title: {
                    text: 'Branch wise activities Last 30 Days',
                    x: -20 //center
                },
                subtitle: {
                    text: '',
                    x: -20
                },
                xAxis: {
                    categories : []
                },
                yAxis: {
                    title: {
                        text: 'TotalValue'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },    

                    tooltip: 
                        {
                             formatter: function() { return ' ' +
                                'EndDate: ' + this.x + '<br />' +
                                'TotalValue: ' + this.y + '<br />' +
                                'zreadactivity: ' + this.series.name;
                             }
                        },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 100,
                    borderWidth: 0
                },


                series: []

            };

            $.getJSON("branchwiseactivityavg", function(json) { 
            options.xAxis.categories = json[0]['data'];
                options.series[0] = json[1];

                chart = new Highcharts.Chart(options);
            });

            });
                </script>

zreadactivity表:

zreadacivity
---------------
Refund
Exchange
Voids
Cancel
Discount
Price Overwrite

1 个答案:

答案 0 :(得分:0)

    一种方法是创建JSON,其中对于系列的数据,每个点被定义为如下数组:
[value_from_TotalValue, value_from_zreadactivity]

并为系列设置keys,如:

series: [{keys: ['y','zreadactivity']}]

并在工具提示的格式化程序中使用this.point.zreadactivity来访问zreadactivity。

    其他选项是在获取JSON数据后在JavaScript中为系列构建此结构。

密钥示例:http://jsfiddle.net/yhx2dp2g/

没有键的示例:http://jsfiddle.net/yhx2dp2g/1/