2

I have two pie charts with different data but same labels and background colors. How can I create a standalone legend (a legend without a chart) using ChartJS so that the legend corresponds to both the pie charts at the same time?

I tried creating a pie chart with the data array set to an array of 0s. However, that causes an empty pie chart to be generated, which takes up a lot of space; so that's a no go.

Any help would be deeply appreciated.

  • it would be easier to answer if you could share the code that creates the two pie charts -- but basically, just dynamically build some html to create the legend based on the options of the charts -- here is an example using google charts --> [How to write your own custom legends for google line chart](https://stackoverflow.com/a/36064828/5090771) – WhiteHat Jul 31 '18 at 18:21
  • Well, it's pretty late. But still, if anyone is looking for an answer you can visit the below link which is for a line chart, the same can be applied for pie charts too https://stackoverflow.com/questions/57528694/chart-js-multiple-charts-with-one-common-legend#57530533 – karthick Aug 16 '19 at 20:10
  • Does this answer your question? [Chart.js Multiple charts with one common legend](https://stackoverflow.com/questions/57528694/chart-js-multiple-charts-with-one-common-legend) – LeeLenalee Nov 02 '21 at 23:23

0 Answers0