为什么我的jschart与json不起作用?

时间:2016-06-23 10:45:45

标签: arrays json jscharts

我遵循了本网站的教程:
(( [^ ])+ )

这是我现在的问题:

<kml  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">

json在jsfiddle ..

http://kushagragour.in/blog/2013/06/getting-started-with-chartjs/

1 个答案:

答案 0 :(得分: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')行试图调用它不知道的函数。