admin管理员组文章数量:1200964
I have the following EChart in my Angular application:
var option = {
xAxis: {
type: 'category',
data: ["A", "B", "C", "D", "E"]
},
yAxis: {
type: 'value',
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
formatter: (params) => {
return (
"Text One" +
'<br/>' +
params[0].name
);
},
},
series: [
{
data: [1, 2, 3, 4, 5],
name: 'value',
stack: 'one',
type: 'bar',
tooltip: {
formatter: (params) => {
return (
"Text One" +
'<br/>' +
params[0].name
);
},
},
},
{
data: [0, 1, 2, 3, 4],
name: 'prediction',
stack: 'one',
type: 'bar',
tooltip: {
formatter: (params) => {
return (
"Text Two" +
'<br/>' +
params[0].name
);
},
},
},
],
};
I basically have two series
and my question is how I can format the tooltip
for each series specifically.
In my example only "Text 1" is shown from the first series.
I have the following EChart in my Angular application:
var option = {
xAxis: {
type: 'category',
data: ["A", "B", "C", "D", "E"]
},
yAxis: {
type: 'value',
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
formatter: (params) => {
return (
"Text One" +
'<br/>' +
params[0].name
);
},
},
series: [
{
data: [1, 2, 3, 4, 5],
name: 'value',
stack: 'one',
type: 'bar',
tooltip: {
formatter: (params) => {
return (
"Text One" +
'<br/>' +
params[0].name
);
},
},
},
{
data: [0, 1, 2, 3, 4],
name: 'prediction',
stack: 'one',
type: 'bar',
tooltip: {
formatter: (params) => {
return (
"Text Two" +
'<br/>' +
params[0].name
);
},
},
},
],
};
I basically have two series
and my question is how I can format the tooltip
for each series specifically.
In my example only "Text 1" is shown from the first series.
Share Improve this question edited Sep 15, 2020 at 13:05 mrks asked Sep 15, 2020 at 12:35 mrksmrks 5,61113 gold badges59 silver badges80 bronze badges2 Answers
Reset to default 12If you use tooltip trigger 'axis', 'params' in the formatter function argument would be an array containing series tooltip information.
If you want to format the first series, you can access params[0]. Similarly if you want to format the second series, you can access params[1].
See example below:
var option = {
xAxis: {
type: "category",
data: ["A", "B", "C", "D", "E"],
},
yAxis: {
type: "value",
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
formatter: (params) => {
return `
Tooltip: <br />
${params[0].seriesName}: ${params[0].value}<br />
${params[1].seriesName}: ${params[1].value}
`;
},
},
series: [
{
data: [1, 2, 3, 4, 5],
name: "model",
stack: "one",
type: "bar",
},
{
data: [0, 1, 2, 3, 4],
name: "prediction",
stack: "one",
type: "bar",
},
],
};
There are two types of tooltip trigger ('item' and 'axis')
Please use tooltip.trigger = 'item', to display tooltip individually for different series.
tooltip.trigger='axis' is used to display a common tooltip with all series data at a given axis level.
本文标签: javascriptEChart series with different tooltipStack Overflow
版权声明:本文标题:javascript - EChart series with different tooltip - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738619610a2103114.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论