1

I want to add the values which I get from a database.These values from the database are stored in a separate array.So how should I write the code so that I can put values in the data field which can then be plotted. Also I want to change the labels array to the values contained in a separate array.

<body>
<canvas id="myChart" width="1000" height="400" style="border:2px solid green"></canvas>

<script>

var data = {
    labels : ["January","February","March","April","May","June","August"],
    datasets : [
        {
            fillColor : "rgba(220,0,220,0.5)",
            strokeColor : "rgba(0,0,0,1)",
            pointColor : "rgba(220,20,220,1)",
            pointStrokeColor : "#fff",
            data : [0,9,0,8,56,55,40]
        },
        {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : [100,100,100,19,96,27,100]
        }
    ]
}
var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).Line(data);

</script>
</body>
4

1 回答 1

1

首先 你需要用数据替换数据:[0,9,0,8,56,55,40] :[data_array1]

data_array1 是来自数据库的 data_string,您只需将该数据数组转换为 highchart 可接受的格式。为此,您需要从数据库中获取数据,用逗号(,)将其分解,它将返回一个类似于 0,9,0,8,56,55,40 的字符串,只需回显它数据:[数据数组1]

于 2013-07-30T11:32:18.503 回答