Closed surendarviki closed 6 years ago
No, this is not implemented. What is your use case?
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.
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.
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?
@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.
I'm glad you like it! I'll be happy to write a few tests and send a pull request soon :)
This can be closed, no?
Happy this feature is now available. Thank you ppl.
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.
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.
Is there a possibility to group the legends? Instead of having 1 legend for 1 line can v have 1 legend for multiple lines?