echarts报错,Uncaught Error: series.type should be specified?

我本来想模仿echarts官方实例折线图中的这个例子:

clipboard.png

链接在此:http://echarts.baidu.com/demo...

然后这是我的代码:

<div id="myEchart" style="height: 500px;width: 100%;-webkit-tap-highlight-color: transparent;user-select: none;position: relative;background: rgba(252, 252, 252, 0);"></div>
var myChart = echarts.init(document.getElementById('myEchart'));

function randomData() {
    now = new Date(+now + oneDay);
    value = value + Math.random() * 21 - 10;
    return {
        name: now.toString(),
        value: [
            [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'),
            Math.round(value)
        ]
    }
}

var data = [];
var now = +new Date(2017, 11, 3);
var oneDay = 24 * 3600 * 1000;
var value = Math.random() * 1000;
for (var i = 0; i < 1000; i++) {
    data.push(randomData());
}

option = {
    title: {
        text: '动态数据 + 时间坐标轴'
    },
    tooltip: {
        trigger: 'axis',
        formatter: function (params) {
            params = params[0];
            var date = new Date(params.name);
            return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' : ' + params.value[1];
        },
        axisPointer: {
            animation: false
        }
    },
    xAxis: {
        type: 'time',
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        boundaryGap: [0, '100%'],
        splitLine: {
            show: false
        }
    },
    series: [{
        name: '模拟数据',
        type: 'pie',
        showSymbol: false,
        hoverAnimation: false,
        data: data
    }]
};

setInterval(function () {

    for (var i = 0; i < 5; i++) {
        data.shift();
        data.push(randomData());
    }

    myChart.setOption({
        series: [{
            data: data
        }]
    });
}, 1000);

结果一运行就出现了标题的报错,还请各位大侠不吝赐教!

阅读 18.3k
2 个回答
myChart.setOption(option) //自己要定义,定时器只是为了动态改变数据
myChart.setOption({
    series: [{
        data: data
    }]
});
myChart.setOption({
    series: [{
        data: data
    }]
});

这里没有指定seriestype

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏