plot2() { const limit2 = this.tableData.length; let y0 = []; let x0 = []; for (let i = 0; i <= limit2 - 1; i++) { y0.push(parseFloat(this.tableData[i].flux)); x0.push(parseFloat(this.tableData[i].date)); } console.log(y0) console.log(x0) let z1 = []; for (let i = 0; i < x.length; i++) {z1.push([x0[i],y0[i]]);} const myChart2 = echarts.init(document.getElementById('chart2')); const option2 = { title: { text: '涌水量-时间' }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, yAxis: { type: 'value', name: '涌水量' }, xAxis: { type: 'time', // 自定义时间格式 axisLabel: { formatter: function (value) { return echarts.format.formatTime('yyyy-MM-dd', value); } }, name: '时间' }, series: [{ data: z1, type: 'line', name: '涌水量', yAxisIndex: 0 }, ] } myChart2.setOption(option2) },这段代码的日期无法正常显示
时间: 2024-01-12 14:02:43 浏览: 68
matplotilb中fig,ax = plt.subplots()的使用
这段代码中,x变量和z1数组的长度不一致,应该改为x0数组。另外,xAxis的type应该为category,而不是time。正确的代码如下:
```
plot2() {
const limit2 = this.tableData.length;
let y0 = [];
let x0 = [];
for (let i = 0; i <= limit2 - 1; i++) {
y0.push(parseFloat(this.tableData[i].flux));
x0.push(this.tableData[i].date);
}
console.log(y0);
console.log(x0);
let z1 = [];
for (let i = 0; i < x0.length; i++) {
z1.push([x0[i], y0[i]]);
}
const myChart2 = echarts.init(document.getElementById('chart2'));
const option2 = {
title: {
text: '涌水量-时间'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
}
},
yAxis: {
type: 'value',
name: '涌水量'
},
xAxis: {
type: 'category',
data: x0,
name: '时间'
},
series: [{
data: z1,
type: 'line',
name: '涌水量',
yAxisIndex: 0
}]
};
myChart2.setOption(option2);
}
```
阅读全文