amcharts / amcharts5

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

XY chart column label height changes to default after refreshing the chart series data #1722

Closed Garima-github-24 closed 3 weeks ago

Garima-github-24 commented 1 month ago

Hi,

I am using the XY chart column series adapter to set the column height based on a condition like below:

series.columns.template.adapters.add('fill', function (fill, target) {
      let dataItem = target.dataItem;
// Set condition here based on dataItem.dataContext
      if (condition) {
        target.set('height',18);
        target.set('cursorOverStyle', 'default');
      }
      return fill;
    });

In this case, the specific column has an increased height of 18 when chart is first loaded. But when we refresh the chart series data using this.chart.series.getIndex(0).data.setAll(this.chartData), the height gets reset to default 12px (height set for all columns) randomly. While the cursorOverStyle is still 'default' as set for that specific column.

Kindly confirm if this is a bug with amcharts 5.

martynasma commented 1 month ago

Why not use an adapter for height straight up?

series.columns.template.adapters.add("height", function(height, target) {
  let dataItem = target.dataItem;
  if (condition) {
    return 18;
  }
  return height;
})
Garima-github-24 commented 1 month ago

I tried your above solution. In this case, target.dataItem is undefined and I need to set my condition based on target.dataItem.dataContext. Hence, it's of no use for my scenario.

Also, in my solution using

 series.columns.template.adapters.add('fill', function (fill, target) {
      let dataItem = target.dataItem;
// Set condition here based on dataItem.dataContext
      if (condition) {
        target.set('height',18);
        target.set('cursorOverStyle', 'default');
      }
      return fill;
    });

I checked by debugging, the height is still set to 18 for specific column but at time of rendering it's getting reset to default 12 sometimes.

martynasma commented 1 month ago

Column height is set by series. If it happens after fill adapter kicks in, your target.set("height", 18) is overwritten.

Thus the need to have separate adapter for height.

And the data item should be present in all column adapters:

series.columns.template.adapters.add("height", function(height, target) {
  console.log(target.dataItem.dataContext);
  return height;
})
Garima-github-24 commented 1 month ago

Data item was undefined sometimes. Used null check to rectify. Thanks a lot, it's working as expected.

github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.