apache / apache/echarts

[Bug] ec-canvas 使用onInit 方法初始化成功之后, setOption 设置notMerge为true报错

Open
#21,129 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
67.3k
Forks
19.8k
Avg merge
15h 17m
Merged PRs (30d)
5

Description

### Version

5.3.3

### Link to Minimal Reproduction

https://github.com/ecomfe/echarts-for-weixin/issues/962

### Steps to Reproduce

报错内容

Image

wxml
```
改变图表参数

```

wxss
```
.chart-fa-view {
width: 100%;
height: 566rpx;
}
#mychart-dom-line {
width: 100%;
height: 566rpx;
}
```
js
```
import * as echarts from "../../ec-canvas/echarts";

const app = getApp();
let customChart = null;
function initChart(canvas, width, height, dpr) {
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr, // new
});
canvas.setChart(chart);

var option = {
title: {
text: "测试下面legend的红色区域不应被裁剪",
left: "center",
},
legend: {
data: ["A", "B", "C"],
top: 50,
left: "center",
backgroundColor: "red",
z: 100,
},
grid: {
containLabel: true,
},
tooltip: {
show: true,
trigger: "axis",
},
xAxis: {
type: "category",
boundaryGap: false,
axisTick: {
show: false,
},
axisLabel: {
color: "#86909C",
},
// show: false
},
yAxis: {
x: "center",
name: "",
type: "value",
splitLine: {
lineStyle: {
color: "#ccc",
type: "dashed",
},
},
// show: false
},
dataset: {
source: [
["时间", "A", "B"],
["周一", 43.3, 85.8],
["周二", 83.1, 73.4],
["周三", 86.4, 65.2],
["周四", 72.4, 53.9],
],
},
series: [
{
name: "A",
type: "line",
smooth: true,
},
{
name: "B",
type: "line",
smooth: true,
},
],
};
chart.setOption(option);
customChart = chart;
return chart;
}
function getSeries(val) {
if (val % 2 === 0) {
return [
{
name: "A",
type: "line",
smooth: true,
},
{
name: "B",
type: "line",
smooth: true,
},
];
}
return [
{
name: "C",
type: "line",
smooth: true,
},
];
}
function getData(val) {
if (val % 2 === 0) {
return [
["时间", "A", "B"],
["周一", 43.3, 85.8],
["周二", 83.1, 73.4],
["周三", 86.4, 65.2],
["周四", 72.4, 53.9],
];
}
return [
["时间", "C"],
["周一", 90],
["周二", 78],
["周三", 51],
["周四", 12],
];
}

Page({
onShareAppMessage: function (res) {
return {
title: "ECharts 可以在微信小程序中使用啦!",
path: "/pages/index/index",
success: function () {},
fail: function () {},
};
},
data: {
ec: {
onInit: initChart,
},
a: 0,
},

onReady() {},
setChartData() {
this.data.a++;
customChart.setOption(
{
series: getSeries(this.data.a),
dataset: {
source: getData(this.data.a),
},
},
true
);
},
});
```

### Current Behavior

当图表需要更换 series ,setOption 之后,图表会带上没更换之前的 serises 我setOption 设置notMerge 直接报错

### Expected Behavior

设置 notMerge不报错

### Environment

```markdown
- OS:
- Browser:
- Framework:
```

### Any additional comments?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the setOption call in setChartData and trace the notMerge path used by the ec-canvas/echarts entry point. Compare the initial series with the replacement series in the reproduction; done means notMerge no longer throws and the old series is removed when the chart is updated.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.