0

我遵循了这个网站的教程:http:
//kushagragour.in/blog/2013/06/getting-started-with-chartjs/

这是我目前的jsfiddle:

<div style="width: 500px; height: 500px;">
    <canvas id="canvas"></canvas>
</div>
var lineChartData = {
    labels : ["January","February","March","April","May","June","July"],
    datasets : [
        {
            fillColor : "rgba(220,220,220,0.5)",
            strokeColor : "rgba(220,220,220,1)",
            pointColor : "rgba(220,220,220,1)",
            pointStrokeColor : "#fff",
            data : myData.mapProperty('rank')
        },
        {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : [28,48,40,19,96,27,100]
        }
    ]

};

var myLine = new    Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);

json在jsfiddle中..

http://jsfiddle.net/vrwjfg9z/2575/

4

1 回答 1

0

对您的 js 进行一些快速更改:

Array.prototype.mapProperty = function(property) {
    return this.map(function (obj) {
        return obj[property];
    });
};

var myData = [{
    "date": "02-03-2013",
    "rank": 213869,
    "sites-linking": 100
}];

var lineChartData = {
    labels : ["January","February","March","April","May","June","July"],
    datasets : [{
            fillColor : "rgba(220,220,220,0.5)",
            strokeColor : "rgba(220,220,220,1)",
            pointColor : "rgba(220,220,220,1)",
            pointStrokeColor : "#fff",
            data : myData.mapProperty('rank')
        }, {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : [28,48,40,19,96,27,100]
    }]
};

var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);

var myData = []没有语句分隔符 -;

此外,将 mapProperty 声明移到其调用上方。在小提琴中,它位于文件的末尾。该行data : myData.mapProperty('rank')正在尝试调用它不知道的函数。

于 2016-06-23T11:23:27.640 回答