echarts legend不显示
时间: 2023-10-08 08:05:29 浏览: 132
echarts legend 排列问题
如果echarts legend不显示,可能有两种情况解决办法。
情况一,要保证legend中的data与series中name相同。你需要在options中设置legend的data属性,确保它与series中的name属性相匹配。例如:
```
var options = {
legend: {
data: ["2018", "2019"]
},
series: [
{
name: "2018",
data: [10, 20, 30, 40, 50]
},
{
name: "2019",
data: [30, 60, 70, 60, 80]
}
]
}
myCharts.setOptions(options)
```
这样设置后,legend应该能正确显示。
情况二,如果legend中的data是动态加入的,可能会导致不显示。解决办法是不能单独添加data,需要将legend一起整体添加到options中。例如:
```
var options = {
series: [
{
name: "2018",
data: [10, 20, 30, 40, 50]
},
{
name: "2019",
data: [30, 60, 70, 60, 80]
}
]
}
var legend = {
data: legendData
}
options.legend = legend;
myCharts.setOptions(options)
```
通过将legend整体添加到options中,应该能够解决legend不显示的问题。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* *2* [echarts legend不显示](https://blog.csdn.net/qq_41818857/article/details/118210239)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文