echarts: Legend is not displayed when name repeats

Version

5.4.0

Link to Minimal Reproduction

https://codepen.io/Mykhailo-codepen/pen/rNrPbeV

Steps to Reproduce

1)create pie chart with legend 2)add data to legend with elements which has same name.

Current Behavior

If name of legend repeats it will be omitted and only first will be shown

Expected Behavior

All names of legend are displeyed even they repeats

Environment

Problem in all browsers independent of Framework

Any additional comments?

image

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 17

Most upvoted comments

I agree with @ptulou. In our use case series names are unpredictable, easily repeated, and customizable by the user. It would be nice if the legend could work with the series ID. Currently, the legend breaks when there are duplicate names.

I have a similar case. In my case I’ve got many series on a chart. Some of the series are named line plots. Some of them show the results of analytics on the data using mark areas, and such. We want to be able to toggle the analytics on and off separately from the data through the legend. But, if the user happens to name the data trend the same thing as the analyitic, we get this behavior where the two are treated as one thing. It would be great if we could supply an id value to the legend data so that the id could be used for uniqueness and the name could just be for display. Ideally, that id value could be the id of the series so that we’re linking the two on something more concrete than the user modifyiable name?

I have requirements. I don’t decide by myself

Thank you! This workaround I will use like last option because:

  1. it add spaces to legend and it will be not symmetrical
  2. amount of names are dynamic (can be more than 10) and I need to create additional method which handle all this workaround

@Mykhaylo12 : Have a better workaround using legend’s formatter. Adding suffix for name, then using formatter to cut the suffix by delimiter

  legend: {
    formatter: function (name) {
        return name.split('-')[0];
    }
  },
  tooltip: {},
  dataset: {},
  xAxis: { type: 'category' },
  yAxis: {
    name: 'Test label',
    nameLocation: 'middle',
    nameGap: 100
  },
  series: [{ type: 'bar',
    name: "Apple-id1",
    data: [1,2,3,4,5,6,7,8,9,10,11,12]
  },
  { type: 'bar',
    name: "Apple-id2",
    data: [1,2,3,4,5,6,7,8,9,10,11,12]
  },
  ]
};

My previous screenshot only had 2 series. I’m already using the type “scroll” for legend. This helps but it still is just a workaround. We also have that same issue on tooltips: image

In order to patch this too we could use the tooltip formater. It feels tacky but allows you to reach the wanted result.

image Another issue with my specific workaround: If you need to add a suffix for time intervals then consider adding the year because if you select the same month of 2 different years then the system will break.

I have a similar issue, in my case I’ve created a chart used to compare data in time. The series names are the same “measureName+deviceName” but in the end they are 2 different series. The only thing that makes them differ is the actual range in which they are visualized but placing that range into that name makes the label too long. I would like to keep the 2 legend items with the same name but different color so the final user can decide to show/hide what he doesn’t want to see in that moment: image