I want to hide the legend for a specific line where I wanted to hide the label and it’s icon inside the chart. For the rest of the legends will be shown normally inside the chart. As you can see, I’m able to hide the labels but not the icon. I want to solve this issue where I wanted to hide both of it instead of hiding only the labels of the legends
<div id="chart">
<apexchart type="rangeArea" height="400" :options="chartOptions" :series="combinedSeries(item, 'related_keyword_data')" />
</div>
legend: {
show: true,
formatter: function(seriesName) {
// List of series names to hide
const hiddenSeries = ['CI_70', 'CI_90'];
for (let hidden of hiddenSeries) {
if (seriesName.includes(hidden)) {
return '';
}
}
return seriesName; // Return the original series name to show the legend
},
onItemClick: {
toggleDataSeries: true
},
},
If I declare it inside of the series, it will not be affected and I think it is because the chartOption{} is the main declaration for all the behaviors of the chart. So I have to declare it inside of the chartOption{}. Same goes trying to set opacity for specific lines, it won’t work if declare inside of the series.
{
name: `${relatedItem.keyword} - CI_70`,
data: ci_70,
type: 'rangeArea',
color: color,
},
{
name: `${relatedItem.keyword} - CI_90`,
data: ci_90,
type: 'rangeArea',
color: color,
},
I’m trying to hide for a specific series instead of hiding all of them but I can only hide the labels and not the icons together. I cannot find answers to hide the labels and it’s icons for specific series of a line
2
Answers
The legend marker can be disabled for a specific series, by setting its
legend.marker.size
to0
.For a multiple series chart, the value of
legend.marker.size
may be an arraywith sizes for each of the series (the default value is 7). Thus, for instance:
will cancel the marker for the 3rd and 5th series.
Unfortunately, the option
legend.itemMargin.horizontal
doesn’t allow its value to bean array with different values for different series. The default value is 5, so there
will be a space of double that value in place of the missing legend item.
A possible solution for that is to set the value to zero and add spacing between items
by adding a non-breaking space character to each legend text. Here’s an example,
hiding the same third legend item:
Here’s a demo of those options in snippet, with the hidden series indices set in a dynamic
hidden
array:If you just want to hide legend and its associated icon then you just can try like below:
or if you just want to do it for specific series then you can do it like below:
hide legends through css like: