我想为pie highchart codeigniter显示动态图例和工具提示

时间:2014-12-24 09:30:26

标签: jquery codeigniter highcharts

"这是我的代码"

public function data()
    {
        .....
        $data = $this->data->get_data($month1, $year1, $month2, $year2,$CtypeID);
        $category = array();
        $category['name'] = 'Category';
        $series1 = array();
        foreach ($data as $row)
        {
            $legend_date = date("F-y", strtotime($row->CreatedOn));         
            $category['data'][] =$legend_date;
            $series1['data'][] = $row->ID;
            $series1['name'] = 'Sales';

        }

        $result = array();
        array_push($result,$category);
        array_push($result,$series1);
        print json_encode($result, JSON_NUMERIC_CHECK);
    }
$(document).ready(function() {
        $('#pie').click(function(){             
            var options = {
                chart: {
                    renderTo: 'container2',
                    type: 'pie',
                    marginRight: 130,
                    marginBottom: 25
                },
                title: {
                    text: '',
                    x: -20 //center
                },
                subtitle: {
                    text: '',
                    x: -20
                },
                xAxis: {
                    categories: [],
                     labels: {
           enabled: false
          }
                },
                yAxis: {
                    title: {
                        text: 'No Of Sales'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    formatter: function() {
                     return this.series.name +': '+ this.y;
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 100,
                    borderWidth: 0,
                },
        plotOptions: {
            series: {
                 animation: {
                    duration: 2000
                }
            },
             pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                           format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    },
                    showInLegend: true,
                },
        },
               series: []
            }
            var month1 = document.getElementById('month1').value;
            var year1  = document.getElementById('year1').value;
            var month2 = document.getElementById('month2').value;
            var CtypeID = document.getElementById('CtypeID').value;
            var value = 'month1='+month1+'&year1='+year1+'&month2='+month2+'&year2='+year2+'&CtypeID='+CtypeID;  
            $.getJSON("data", value, function(json) {
                options.xAxis.categories = json[0]['data'];
                options.series[0] = json[1];
                chart = new Highcharts.Chart(options);
            });
       });
        });     

问题是此代码输出slice而不是动态图例。

0 个答案:

没有答案