#1410·chartist

Support plot legends

Author: umayrhCreated May 26, 2023Updated Mar 11, 2025
Labelsenhancement

Would you like to work on this feature?

  • Check this if you would like to implement a PR, we are more than happy to help you go through the process.

What problem are you trying to solve?

Since chartist-plugin-legend seem inactive, and is incompatible with Chartist v1 [1], there doesn't seem to be a way to put legends in Chartist plots anymore. Chart legends should be part of Chartist core lib and not a plugin since it's essential to make non-trivial plots meaningful.

[1] Upgrading the chartist CSS and JS sources in https://codepen.io/chimmer/pen/QVvMgz?editors=1111 breaks the demo

Describe the solution you'd like

By default, the legend should be constructed from the name field provided in the series list, and default to using the alpha-numerated classnames (so, Plot A, Plot B etc).

    new Chartist.LineChart(
      '#chart',
      {
        labels: ['a', 'b', 'c'],
        series: [{'name': 'Plot 1', data: [1, 3, 4, 7, 11, 18]}, {'name': 'Plot 2', data: [1, 2, 3, 5, 8, 13]]
      }, {
        fullWidth: false,
        },
    });

Describe alternatives you've considered

No response

Documentation, Adoption, Migration Strategy

No response