amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
Other
342 stars 91 forks source link

How to get constant width columns in DateAxis? #280

Closed someden closed 2 years ago

someden commented 2 years ago

Example: https://stackblitz.com/edit/react-ho61sf?file=src%2FChart.js

What I have: Screenshot 2022-02-11 at 19 29 09

What I need: Screenshot 2022-02-11 at 19 29 34

I have tied to set width:

    series.columns.template.setAll({
      width: am5.percent(70), // <- NOT WORK
      templateField: 'columnSettings',
    });

It works only after changes in select.

Check, please, example. What did I miss?

martynasma commented 2 years ago

Well, the issue here is that when you dynamically set baseInterval on a DateAxis it takes only in next frame, whereas setting data makes it get parsed immediately.

We'll need to figure out a way to do it properly, whether by a workaround or by internal changes.

In the interim, delaying setting data a few milliseconds seems to do the trick (although we'll be looking for a better workaround):

setTimeout(() => {
  seriesRef.current?.data.setAll(data);
}, 10);

A couple of other things that jumped out at me:

1) DateAxis requires baseInterval. Even if you set empty data, it may result in a nasty critical error if it's not there right from the start.

2) No need to set data on a DateAxis. It's not using it, so it's a waste of CPU.

Will get back to you on the first issue.

someden commented 2 years ago

Thanks for workaround. And thanks for correction about setting data on a DateAxis. I copied it from the docs, but didn't notice that it's related only for CategoryAxis.

martynasma commented 2 years ago

Fixed in 5.1.5.

[5.1.5] - 2022-02-22

Added

Changed

Fixed

Full change log.

Download options.

Make sure you clear your browser cache after upgrading. And feel free to contact us again if you are still experiencing this issue.