当前位置:网站首页>Echart line chart: when multiple lines have the same name, the legend is still displayed
Echart line chart: when multiple lines have the same name, the legend is still displayed
2022-06-13 06:07:00 【HaanLen】
By default
option = {
title: {
text: 'Stacked Line'
},
tooltip: {
trigger: 'axis'
},
legend: {
show: true
// data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {
}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Union Ads',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Video Ads',
type: 'line',
stack: 'Total',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: 'Direct',
type: 'line',
stack: 'Total',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine',
type: 'line',
stack: 'Total',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
When the polyline has the same name , Only one... Will be displayed if the legend is the same
option = {
title: {
text: 'Stacked Line'
},
tooltip: {
trigger: 'axis'
},
legend: {
show: true
// data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {
}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Video Ads',
type: 'line',
stack: 'Total',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: 'Direct',
type: 'line',
stack: 'Total',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine',
type: 'line',
stack: 'Total',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
When the line chart has the same name , Also show all the illustrations .
Solution logic :
series In the series name Set unique value ;legend adopt formatter, Using uniqueness id Get the corresponding name to show ; Floating window passing data Medium value Array settings name To display .
Mainly used legend Of formatter Method
The contents of the floating window also need to be modified
option = {
title: {
text: 'Stacked Line'
},
tooltip: {
trigger: 'axis',
formatter: (params) => {
let arr = [
{
name: '3333',
type: 'line',
text: 'Videot',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Videot',
type: 'line',
text: 'Videot',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Videot1',
type: 'line',
text: 'Videot',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: 'Search Engine',
type: 'line',
text: 'Search Engine',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine1',
type: 'line',
text: 'Search Engine',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
];
let middle = ``;
for (let i = 0; i < params.length; i++) {
let name = arr.find((v) => v.name === params[i].seriesName).text;
middle += `<div> <span> ${
name}</span>: <span>${
params[i].value}</span> </div>`;
}
let content = ` <div> ${
middle} </div>`;
return content;
}
},
legend: {
show: true,
// data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine'],
formatter: (name) => {
let arr = [
{
name: '3333',
type: 'line',
text: 'Videot',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Videot',
type: 'line',
text: 'Videot',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Videot1',
type: 'line',
text: 'Videot',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: 'Search Engine',
type: 'line',
text: 'Search Engine',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine1',
type: 'line',
text: 'Search Engine',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
];
let showText = arr.find((v) => v.name === name).text;
return showText;
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {
}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
name: '3333',
type: 'line',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Videot',
type: 'line',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Videot1',
type: 'line',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: 'Search Engine',
type: 'line',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine1',
type: 'line',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
边栏推荐
- Download and installation of universal player potplayer, live stream m3u8 import
- Echart柱状图:堆叠柱状图value格式化显示
- 微信小程序:基础复习
- 免费录屏软件Captura下载安装
- 本地文件秒搜工具 Everything
- 【MySQL】基础知识小复习
- What happens when the MySQL union index ABC encounters a "comparison operator"?
- [turn] explain awk (1)__ Awk Basics_ Options_ Program segment parsing and examples
- The SQL file of mysql8.0 was imported into version 5.5. There was a pit
- Audio stereo to mono (Audio Dual Channel to mono channel)
猜你喜欢
Echart柱状图:x轴显示value,y轴显示类别
Concurrent programming -- what is threading?
Feel the power of shardingsphere JDBC through the demo
【ONE·Data || 带头双向循环链表简单实现】
Experience of redis installation under Linux system (an error is reported at the same time. The struct redis server does not have a member named XXXX)
Misunderstanding of tongweb due to ease of use
Echart柱状图:echart实现堆叠柱状图
SPI primary key generation strategy for shardingsphere JDBC
微信小程序:点击事件获取当前设备信息(基础)
Zero copy technology
随机推荐
免费录屏软件Captura下载安装
Fusionpbx installation - road to dream
USB 0xc0000011 error
Leetcode planting flowers - simple
Leetcode longest harmonic subsequence simple
Misunderstanding of tongweb due to ease of use
Waterfall flow layout of uni app Homepage
HBuilderX:HBuilderX安装以及其常用插件安装
Leetcode- intersection of two arrays - simple
Kotlin learning notes (1)
Leetcode- complement of numbers - simple
Echart折线图:当多条折线图的name一样时也显示不同的颜色
Why do so many people hate a-spice
Leetcode- third largest number - simple
Leetcode- reverse string - simple
The difference between the increment and decrement operators before and after variables i+, +i, I –, – I
MySQL trigger
Leetcode- distribute cookies - simple
CORS request principle
Leetcode- first unique character in string - simple