如何填写图表javascript表?

时间:2016-02-23 10:58:31

标签: javascript charts

我想用循环完成此表,但它会产生一个错误,你可以帮助我。

Morris.Area({
    element: 'graph-area',
    behaveLikeLine: true,
    gridEnabled: false,
    gridLineColor: '#dddddd',
    axes: true,
    fillOpacity:.7,
    data: [
    for( var i=1;i<10;i++)
    {
        {period: '2010 Q1',  itouch: i},

    }


    ],
    lineColors:['#E67A77','#D9DD81','#79D1CF'],
    xkey: 'period',
    ykeys: ['iphone', 'ipad', 'itouch'],
    labels: ['iPhone', 'iPad', 'iPod Touch'],
    pointSize: 0,
    lineWidth: 0,
    hideHover: 'auto'

});

1 个答案:

答案 0 :(得分:0)

使用中间变量,如:

var myData = [];  
for( var i=1;i<10;i++){
  myData.push({period: '2010 Q1',  itouch: i});
}

Morris.Area({
    element: 'graph-area',
    behaveLikeLine: true,
    gridEnabled: false,
    gridLineColor: '#dddddd',
    axes: true,
    fillOpacity:.7,
    data: myData,
    lineColors:['#E67A77','#D9DD81','#79D1CF'],
    xkey: 'period',
    ykeys: ['iphone', 'ipad', 'itouch'],
    labels: ['iPhone', 'iPad', 'iPod Touch'],
    pointSize: 0,
    lineWidth: 0,
    hideHover: 'auto'
});