CodeYellowBV / chartist-plugin-legend

Legend plugin for Chartist.js.
https://codeyellowbv.github.io/chartist-plugin-legend/
Other
116 stars 62 forks source link

Legend Grouping #38

Closed surendarviki closed 6 years ago

surendarviki commented 7 years ago

Is there a possibility to group the legends? Instead of having 1 legend for 1 line can v have 1 legend for multiple lines?

tarekis commented 7 years ago

No, this is not implemented. What is your use case?

surendarviki commented 7 years ago

i need to show expectation and actual as two line chart for multiple users, If i have one legend for each user it will be helpful instead of having 2 legend for each user.

tarekis commented 7 years ago

If you have a strict alternation in your datasets you can do that with custom functions, which let one legend act for two datasets and CSS. If not, I do not see a solution, nor a proposable API for this kind of grouping.

guimeira commented 7 years ago

I have a similar use case. We had to plot two different prices for the same product, one of them as a solid line and the other as a dashed line of the same color. In that case, it makes sense to have a single legend item representing both series.

I forked the project and implemented this feature using the legendNames option. Now, it also takes an object containing the name property (the text of the legend item) and the series property, which is an array of integers containing the indexes of the series associated with this legend item.

This feature can be used like this:

new Chartist.Line('.ct-chart-line-multipleseries', {
   labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
   series: [
       [12, 9, 7, 8, 5],
       [2, 1, 3.5, 7, 3],
       [1, 3, 4, 5, 6]
   ]
}, {
   fullWidth: true,
   chartPadding: {
      right: 40
   },
   plugins: [
       Chartist.plugins.legend({
          legendNames: [{name: 'Red-ish', series: [0,1]}, {name: 'Yellow', series: [2]}],
       })
   ]
});

Do you think this feature could be added to the main repository? If so, is this API ok?

SpaceK33z commented 7 years ago

@guimeira, wow, that looks nice. Yeah, the API is fine I think. I would really appreciate a PR :). Note that you'll need to add one or more tests, since the code is a bit too tricky to go untested.

I'm fairly busy these days so it can take some days for me to review.

guimeira commented 7 years ago

I'm glad you like it! I'll be happy to write a few tests and send a pull request soon :)

amichair commented 6 years ago

This can be closed, no?

surendarviki commented 6 years ago

Happy this feature is now available. Thank you ppl.

tarekis commented 6 years ago

Ugh well, yeah that is actually available on master, but not on npm yet. I wanted to update the repo with a .npmignore file and release it properly.. if you need this right now please use the commit sha as version, but I will check if can release this today.

SpaceK33z commented 6 years ago

I wanted to update the repo with a .npmignore file

This is not necessary, in the package.json there already is a files property which is a whitelist of files to be uploaded to npm instead of a blacklist.