echarts.min.js:22 Uncaught (in promise) Error: series.type should be specified.?

<script>

export default {

data () {

return {

chartInstance: null,

allData: null

}

},

mounted () {

this.initChart()

this.getData()

},

destroyed () {

this.initChart()

this.getData()

},

methods: {

initChart () {

this.chartInstance = this.$echarts.init(this.$refs.stationyield_ref, 'chalk')

const initOption = {

tooltip: {

trigger: 'axis'

},

legend: {

textStyle: {

color: '#4c9bfd'

},

right: '10%'

},

grid: {

left: '3%',

top: '30%',

right: '4%',

bottom: '1%',

containLabel: true

},

xAxis: {

type: 'category',

boundaryGap: false,

axisTick: {

show: false

},

axisLabel: {

color: '#4c9bfd'

},

axisLine: {

show: false

}

},

yAxis: {

type: 'value',

axisTick: {

show: false

},

axisLabel: {

color: '#4c9bfd'

},

axisLine: {

show: false // 去除轴线

},

splitLine: {

lineStyle: {

color: '#012f4a'

}

}

},

series: [

{

type: 'line',

smooth: true

}

]

}

this.chartInstance.setOption(initOption)

},

async getData () {

const { data: ret } = await this.$http.get('http://127.0.0.1:8888/api/stock')

console.log(1111)

this.allData = ret

this.updateChart()

},

updateChart () {

const xAxisValue = this.allData.name

const yAxisValue = this.allData.sales

const dataOption = {

xAxis: {

data: xAxisValue

},

series: [

{

type: 'line',

data: yAxisValue

}

]

}

this.chartInstance.setOption(dataOption)

}

},

adapterChart () {

const adapterOption = {}

this.chartInstance.setOption(adapterOption)

}

}

</script>

<style lang="less" scoped></style>


回答:

updateChart方法里面只是赋值了数据其它属性也要一起带上

updateChart () {

const xAxisValue = this.allData.name

const yAxisValue = this.allData.sales

//建议将initOption放在data里面,然后这里可以使用this.initOption

this.initOption.xAxis.data = xAxisValue

this.initOption.series[0].data = yAxisValue

this.chartInstance.setOption(this.initOption)

}

以上是 echarts.min.js:22 Uncaught (in promise) Error: series.type should be specified.? 的全部内容, 来源链接: utcz.com/p/934234.html

回到顶部