amcharts / amcharts4

The most advanced amCharts charting library for JavaScript and TypeScript apps.
https://www.amcharts.com/
1.16k stars 322 forks source link

Incorrected calculate numeric scale #2970

Open stakahito opened 4 years ago

stakahito commented 4 years ago

Bug description

ValueAxis incorrectly calculates the numeric scale if it contains more than three stacked ColumnSeries.

const data = [{
  category: 'category',
  value1: 0,
  value2: 0,
  value3: 0,
}];

// Drawing chart with ValueAxis.min = 0 ...
// numeric scale is 0 ~ 1.0

// Update values.
data[0].value1 = 1;
data[0].value2 = 1;
data[0].value3 = 1;

// Transition to new values of existing data items.
chart.invalidateRawData(); // Oops, numeric scale is 0 - 2.5. expected numeric scale is 0 - (3~).

See jsfiddle https://jsfiddle.net/g23adn1t/ for more details. (Click the "change" button.)

Environment

martynasma commented 4 years ago

While there's admittedly an issue, we might not be able to solve it soon. We might come back to this, but for now I suggest you do not use invalidateRawData() but rather replace the whole data set.

Should you need animations played on series, you can call chart.reinit().

stakahito commented 4 years ago

Thank you for your suggestion. For now I'm replacing the whole data set.

Should you need animations played on series, you can call chart.reinit().

Yes, I want animations, but chart.reinit() is animations from 0 value every time. :cry:

When calculating the range, I think we need to add some logic around here to determine if the series is a stack. I'll try to resolve this problem and make a pull request this weekend. https://github.com/amcharts/amcharts4/blob/9656bf65e4dd8f98ac2ec438e855bf59da613f11/src/.internal/charts/axes/ValueAxis.ts#L1184-L1189

martynasma commented 4 years ago

I'll try to resolve this problem and make a pull request this weekend.

Thank you for the effort. Unfortunately, we do not accept PR due to a number of reasons :(

stakahito commented 4 years ago

I understand, but I'm hoping that this issue will be resolved early, so is there any way I can contribute?

martynasma commented 4 years ago

If you manage to solve this, do a PR. While we won't be able to merge it (this repo is just for distribution, it's not actual dev repo), we might review what you did and whether it makes sense / is safe to include into main code base.

stakahito commented 3 years ago

Sorry for the delayed response.

This issue was related to the part near the ValueAxis base and seemed to be difficult to solve. I changed it to give up the animation and call chart.validateData() as a workaround.

I hope this problem will be resolved someday...