Skip to content

Add the ability to draw a line as legend symbol#4163

Closed
apetitpa wants to merge 2 commits intochartjs:masterfrom
apetitpa:line-style-legend
Closed

Add the ability to draw a line as legend symbol#4163
apetitpa wants to merge 2 commits intochartjs:masterfrom
apetitpa:line-style-legend

Conversation

@apetitpa
Copy link

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.

Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work as expected for dashed lines?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either it looks great with dashed lines, can you post screenshots?

Copy link
Member

@simonbrunel simonbrunel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either it looks great with dashed lines, can you post screenshots?

@apetitpa
Copy link
Author

apetitpa commented Aug 9, 2017

I'm sorry but I don't have time to go any further with this PR.

@apetitpa apetitpa closed this Aug 9, 2017
@apetitpa apetitpa deleted the line-style-legend branch August 9, 2017 15:05
@simonbrunel simonbrunel removed this from the Version 2.7 milestone Aug 28, 2017
@dhniels
Copy link

dhniels commented Sep 5, 2017

Why was this closed? This is a much desired feature among developers I know using ChartJS

@apetitpa
Copy link
Author

apetitpa commented Sep 6, 2017

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants