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

DataLabels show wrong value #4647

Closed
gold-development opened this issue Aug 18, 2024 · 1 comment · Fixed by #4648
Closed

DataLabels show wrong value #4647

gold-development opened this issue Aug 18, 2024 · 1 comment · Fixed by #4648
Labels
bug Something isn't working

Comments

@gold-development
Copy link
Contributor

gold-development commented Aug 18, 2024

Description

Starting from Version 3.51.0 and higher The chart is showing the wrong info in the datalabels. It's showing the value of the first series for the 2nd series. Downgrading the version to 3.50.0 fixes the issue.

Steps to Reproduce

  1. Create two series, one line and one column
series: [{
    name: 'Target',
    data: Array(12).fill(0),
    type: 'line',
  }, {
    name: 'Data',
    data: Array(12).fill(0),
    type: 'column',
  }],
  1. fill with data for 12 values
const startValue = 70;
const growthPercentage = .10;
// F = A * ((1 + B) ^ C)
for (let i = 0; i < 12; ++i) {
  options.series[0].data[i] = startValue * Math.pow(1 + growthPercentage, i);
}
options.series[1].data[0] = 50;
  1. show datalabels
dataLabels: {
    enabled: true,
    textAnchor: 'middle',
    formatter: (val) => {
      return val.toFixed(0);
    },
  },

Expected Behavior

Datalabel for series[0] show 70
Datalabel for series[1] shows 50

Actual Behavior

Datalabel for series[0] show 70
Datalabel for series[1] shows 70

Screenshots

Screenshot 2024-08-18 at 23 40 21

Reproduction Link

https://codepen.io/jeffreygoudzwaard/pen/zYVRZqR

@gold-development gold-development added the bug Something isn't working label Aug 18, 2024
@gold-development
Copy link
Contributor Author

gold-development commented Aug 19, 2024

After some debugging I found out that the "val" passed into the datalabels formatter function is wrong. Using the opts.w.config.series with the seriesIndex and dataPointIndex gives back the right value.

dataLabels: {
    enabled: true,
    textAnchor: 'middle',
    formatter: (val, opts) => {
      return opts.w.config.series[opts.seriesIndex].data[opts.dataPointIndex].toFixed(0);
    },
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant