解决方案 »

  1.   

    怎么写都不行,后台返回的都是字符串,即使你返回的也是数组到了前端也是'[1,2,3,4]'这样的字符串,会直接导致JS代码报错。
    要先将这些通过parseJSON转换成数组。具体的parseJSON自己去查一下资料吧。
      

  2.   

     StringBuilder sb = new StringBuilder();
            sb.Append("[");        foreach (DataRowView drv in dt.DefaultView)
            {
                if (type == "data")
                {
                    sb.Append(drv[type].ToString());
                    sb.Append(",");
                }
                else
                {
                    sb.Append("'");
                    sb.Append(drv[type].ToString());
                    sb.Append("',");
                }
            }        return sb.Replace(",", "", sb.Length - 1, 1).Append("]").ToString(); //这里是去掉最后一个多余的逗号(,)
        }
      

  3.   

    那代码就是讲后台的DataRow转换成[1,2,3,4]这样的字符串的。
      

  4.   

    Using Highcharts with PHP and MySQLI like Highcharts. There are many JavaScript-based charting components out there but I particularly enjoyed using this JavaScript library.In this post, I want to step you through how to use Highcharts with PHP and MySQL.<script type="text/javascript">
        var chart;
                $(document).ready(function() {
                    var options = {
                        chart: {
                            renderTo: 'container',
                            defaultSeriesType: 'line',
                            marginRight: 130,
                            marginBottom: 25
                        },
                        title: {
                            text: 'Hourly Visits',
                            x: -20 //center
                        },
                        subtitle: {
                            text: '',
                            x: -20
                        },
                        xAxis: {
                            type: 'datetime',
                            tickInterval: 3600 * 1000, // one hour
                            tickWidth: 0,
                            gridLineWidth: 1,
                            labels: {
                                align: 'center',
                                x: -3,
                                y: 20,
                                formatter: function() {
                                    return Highcharts.dateFormat('%l%p', this.value);
                                }
                            }
                        },
                        yAxis: {
                            title: {
                                text: 'Visits'
                            },
                            plotLines: [{
                                value: 0,
                                width: 1,
                                color: '#808080'
                            }]
                        },
                        tooltip: {
                            formatter: function() {
                                    return Highcharts.dateFormat('%l%p', this.x-(1000*3600)) +'-'+ Highcharts.dateFormat('%l%p', this.x) +': <b>'+ this.y + '</b>';
                            }
                        },
                        legend: {
                            layout: 'vertical',
                            align: 'right',
                            verticalAlign: 'top',
                            x: -10,
                            y: 100,
                            borderWidth: 0
                        },
                        series: [{
                            name: 'Count'
                        }]
                    }
                    // Load data asynchronously using jQuery. On success, add the data
                    // to the options and initiate the chart.
                    // This data is obtained by exporting a GA custom report to TSV.
                    // http://api.jquery.com/jQuery.get/
                    jQuery.get('data.php', null, function(tsv) {
                        var lines = [];
                        traffic = [];
                        try {
                            // split the data return into lines and parse them
                            tsv = tsv.split(/\n/g);
                            jQuery.each(tsv, function(i, line) {
                                line = line.split(/\t/);
                                date = Date.parse(line[0] +' UTC');
                                traffic.push([
                                    date,
                                    parseInt(line[1].replace(',', ''), 10)
                                ]);
                            });
                        } catch (e) {  }
                        options.series[0].data = traffic;
                        chart = new Highcharts.Chart(options);
                    });
                });
    </script><?php
    $con = mysql_connect("localhost","user","");if (!$con) {
      die('Could not connect: ' . mysql_error());
    }mysql_select_db("highcharts", $con);$result = mysql_query("SELECT * FROM highcharts_php");while($row = mysql_fetch_array($result)) {
      echo $row['timespan'] . "\t" . $row['visits']. "\n";
    }mysql_close($con);
    ?>
      

  5.   

    http://blueflame-software.com/blog/using-highcharts-with-php-and-mysql/