Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: Add Data Labels to Scatter Charts #420

Merged

Conversation

ReimaFrgos
Copy link
Contributor

@ReimaFrgos ReimaFrgos commented Oct 19, 2018

New feature to allow labels to be added on Scatter Charts. Should resolve issues #410 and #291

The following options are used for labelling scatter charts:

showLabel:true // Must be set to true or labels will not be shown
dataLabelFormatScatter: custom // Can be set to custom (default), customXY, or XY. 

There are 3 different formats that the label can be set as, and defined using dataLabelScatterFormat:

  • custom - Any custom string, can be unique per plot. e.g. 'My Label'
  • customXY - Any custom string with the XY plot coordinates appended. e.g. 'My Label (X,Y)'
  • XY - Uses the XY plot coordinates as the label. e.g X, Y

For customXY and XY, the plot references are dynamic and will update if the underlying excel data is updated.

Data labels are applied to the Y-Values, and support multiple sets of data in the format.

var data = [
    { name:'X-Axis',    values:[10,12,32,47] },
    { name:'Y-Value 1', values:[13, 20, 21, 25], labels:['Red 1', 'Red 2', 'Red 3', 'Red 4'] },
    { name:'Y-Value 2', values:[21, 22, 25, 49], labels:['Blue 1', 'Blue 2', 'Blue 3', 'Blue 4'] }
];

You do not need to specify the labels object if using dataLabelFormatScatter: XY as only the values are used in the labels.

If using dataLabelFormatScatter: XY every plot point will be labelled.

If using dataLabelFormatScatter: custom or dataLabelFormatScatter: customXY you can choose to label only some plot points by passing in a blank label. Useful when plotting a large number of points e.g.

var data = [
    { name:'X-Axis',    values:[10,12,32,47] },
    { name:'Y-Value 1', values:[13, 20, 21, 25], labels:['Red 1', '', '', 'Red 4'] },
    { name:'Y-Value 2', values:[21, 22, 25, 49], labels:['Blue 1', 'Blue 2', 'Blue 3', ''] }
];

@gitbrent gitbrent self-assigned this Jan 1, 2019
@gitbrent gitbrent added this to the 2.5.0 milestone Jan 1, 2019
gitbrent added a commit that referenced this pull request Jan 1, 2019
@gitbrent gitbrent merged commit d5ebf53 into gitbrent:master Jan 1, 2019
gitbrent added a commit that referenced this pull request Jan 1, 2019
@gitbrent
Copy link
Owner

gitbrent commented Jan 1, 2019

Thanks @ReimaFrgos !

Great job as usual. :-)

I've updated the Chart examples to demo this new feature.

screen shot 2019-01-01 at 15 29 11

ericrockey pushed a commit to WeTransfer/PptxGenJS that referenced this pull request Mar 24, 2020
ericrockey pushed a commit to WeTransfer/PptxGenJS that referenced this pull request Mar 24, 2020
@jsvishal
Copy link

Can this be added for Bubble Chart too?

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.

3 participants