echarts
echarts copied to clipboard
Series data dont apply on legend but data exist on series and legend.
The problem is the series set the data and legend set the data but in the end the legend dont show and have an error Legend data should be same with series name or data name.
charts varsion: 5.5.1
const option = shallowRef<echarts.EChartsCoreOption>({
legend: {
type: 'scroll',
bottom: '0%',
left: 'center',
},
polar: {
radius: [50, '60%'],
startAngle: 90,
},
angleAxis: {
show: false,
},
radiusAxis: {
show: false,
type: 'category',
},
series: {
name: 'Alarms',
type: 'bar',
roundCap: true,
data: {},
coordinateSystem: 'polar',
label: {
show: false,
},
},
graphic: [
{
type: 'text',
left: 'center',
top: '46%',
style: {
text: 'TOTAL',
textAlign: 'center',
fontSize: 22,
fontWeight: 'normal',
fill: '#6A5ACD',
}
},
{
type: 'text',
left: 'center',
top: '51%',
style: {
text: null,
textAlign: 'center',
fontSize: 22,
fontWeight: 'normal',
fill: '#6A5ACD',
}
}
]
})
onMounted(async () => {
data.value = await fetchData()
const chartData = [
{ name: 'Alarms', value: data.value.alarms, },
{ name: 'Readings', value: data.value.readings, },
{ name: 'Smart', value: data.value.smart, },
]
option.value.series.data = chartData
option.value.legend.data = chartData
option.value.angleAxis.max = data.value.total
option.value.graphic[1].style.text = data.value.total
})
https://echarts.apache.org/en/api.html#echartsInstance.setOption ?
https://echarts.apache.org/en/api.html#echartsInstance.setOption ?
I set the option to the chart
you are missing setOption command at the end - Demo