Add the ability to draw a line as legend symbol#4163
Add the ability to draw a line as legend symbol#4163apetitpa wants to merge 2 commits intochartjs:masterfrom apetitpa:line-style-legend
Conversation
This was requested by a client and I found a solution here http://stackoverflow.com/questions/39155400/legends-for-line-charts-in-chart-js and noticed there was no PR about it.
etimberg
left a comment
There was a problem hiding this comment.
A good start at this. Once the comments are addressed and unit tests are added this could be merged
|
|
||
| // Draw pointStyle as legend symbol | ||
| Chart.canvasHelpers.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY); | ||
| } else if (opts.labels && opts.labels.useLineStyle) { |
There was a problem hiding this comment.
I would change this to be
if (opts.labels) {
if (opts.labels.usePointStyle) {
...
} else if (opts.labels.useLineStyle) {
...
}
}| Chart.canvasHelpers.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY); | ||
| } else if (opts.labels && opts.labels.useLineStyle) { | ||
| // Draw line as legend symbol | ||
| ctx.strokeRect(x, y + fontSize / 2, boxWidth, 0); |
There was a problem hiding this comment.
Will this work as expected for dashed lines?
There was a problem hiding this comment.
I'm not sure either it looks great with dashed lines, can you post screenshots?
simonbrunel
left a comment
There was a problem hiding this comment.
Will need to add that new config to the docs and maybe add unit tests.
| Chart.canvasHelpers.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY); | ||
| } else if (opts.labels && opts.labels.useLineStyle) { | ||
| // Draw line as legend symbol | ||
| ctx.strokeRect(x, y + fontSize / 2, boxWidth, 0); |
There was a problem hiding this comment.
I'm not sure either it looks great with dashed lines, can you post screenshots?
|
I'm sorry but I don't have time to go any further with this PR. |
|
Why was this closed? This is a much desired feature among developers I know using ChartJS |
|
@dhniels As I said, I don't have the time to go any further unfortunately. I just borrowed a piece of code from stackoverflow because I thought it would be great to have this feature |
This was requested by a client and I found a solution here http://stackoverflow.com/questions/39155400/legends-for-line-charts-in-chart-js and noticed there was no PR about it.