legend
Configuration Structure
legend: {}show
trueWhether to show or hide the legend container.
showForSingleSeries
falseShow legend even if there is just 1 series.
showForNullSeries
trueAllows you to hide a particular legend if it's series contains all null values.
showForZeroSeries
trueAllows you to hide a particular legend if it's series contains all 0 values.
position
'bottom'Available position options for legend
- top
- right
- bottom
- left
horizontalAlign
'center'Available options for horizontal alignment
- left
- center
- right
floating
falseThe floating option will take out the legend from the chart area and make it float above the chart.
fontSize
'12px'Sets the fontSize of legend text elements
fontFamily
undefinedSets the font-family of legend text elements
fontWeight
400Sets the font-weight of legend text elements
formatter
undefinedA custom formatter function to append additional text to the legend series names
legend: { /* * @param {string} seriesName - The name of the series corresponding to the legend * @param {object} opts - Contains additional information as below * opts: { * seriesIndex * w: { * config, * globals * }, * } */ formatter: function(seriesName, opts) { return [seriesName, " - ", opts.w.globals.series[opts.seriesIndex]] } },
inverseOrder
falseInverse the placement ordering of the legend items.
width
undefinedSets the width for legend container
height
undefinedSets the height for legend container
tooltipHoverFormatter
undefinedA formatter function to allow showing data values in the legend while hovering on the chart. This can be useful when you have multiple series, and you don't want to show tooltips for each series together.
legend: { /* * @param {string} seriesName - The name of the series corresponding to the legend * @param {object} opts - Contains additional information as below * opts: { * seriesIndex, * dataPointIndex * w: { * config, * globals * }, * } */ tooltipHoverFormatter: function(seriesName, opts) { return seriesName + ' - \<strong>' + opts.w.globals.series[opts.seriesIndex][opts.dataPointIndex] + '\</strong>' } },
Note: This feature is only available in shared tooltips (when you have tooltip.shared: true).
customLegendItems
[]Allows you to overwrite the default legend items with this customized set of labels. Please note that the click/hover events of the legend will stop working if you provide these custom legend labels.
clusterGroupedSeries
trueIn a grouped stacked chart, this option gives a visual difference by grouping the legend items in different containers.
clusterGroupedSeriesOrientation
'vertical'Available Options are either "horizontal" or "vertical"
offsetX
-20Sets the left offset for legend container
offsetY
4Sets the top offset for legend container
labels
colors
undefinedCustom text colors for legend labels. Accepts an array of colors where each index corresponds to the series index
markers
size
7Size of the marker point that appears before the legend text
shape
undefinedShape of the marker.
Available Options for shape
- circle
- square
- line
- plus
- cross
- star
- sparkle
- diamond
- triangle
strokeWidth
1Stroke Size of the marker point.
fillColors
undefinedFill Color of the marker point.
customHTML
undefinedCustom HTML element to put in place of marker
markers: customHTML: function() { return '\<span className="custom-marker">\<i className="fas fa-chart-pie">\</i>\</span>' } },
onClick
undefinedFire an event when legend's marker is clicked
markers: onClick: function(chart, seriesIndex, opts) { console.log("series- " seriesIndex + "'s marker was clicked") } },
offsetX
0Sets the left offset of the marker
offsetY
0Sets the top offset of the marker
itemMargin
horizontal
5Horizontal margin for individual legend item.
vertical
4Vertical margin for individual legend item.
onItemClick
toggleDataSeries
trueWhen clicked on legend item, it will toggle the visibility of the series in chart.
onItemHover
highlightDataSeries
trueWhen hovered on legend item, it will highlight the paths of the hovered series in chart.