Jun OUYANG FAN
Jun OUYANG FAN

Reputation: 1

How can I know the current group interval in amcharts5?

I'm working with amCharts and I've encountered an issue regarding the detection of the currently used group interval after zooming in or out. Specifically, when I zoom in or out, the group interval automatically changes, for example, from "day" to "hour". What I want to achieve is to accurately detect and log the current group interval being used after these zoom actions, so in this case, it would be "hour" after zooming in.

Here’s what I have tried so far:

const xAxis = chart.xAxes.push(
  am5xy.DateAxis.new(root, {
    groupData: true,
    groupIntervals: [
      { timeUnit: "minute", count: 1 },
      { timeUnit: "minute", count: 10 },
      { timeUnit: "hour", count: 1 },
      { timeUnit: "day", count: 1 },
      { timeUnit: "week", count: 1 },
      { timeUnit: "month", count: 1 },
      { timeUnit: "year", count: 1 }
    ],
    baseInterval: { timeUnit: "minute", count: 1 },
    renderer: am5xy.AxisRendererX.new(root, {}),
    tooltip: am5.Tooltip.new(root, {}),
  })
);

xAxis.events.on("groupintervalchanged", function() {
      const currentInterval = xAxis.get("baseInterval").timeUnit;

      console.log(currentInterval); // It consistently logs "minute" even when the interval is visually set to "hour" or "day".

      if (currentInterval === "hour") { 
          seriesC.bullets.push(function () {
              const graphics = am5.Circle.new(
                  root,
                  {
                      fill: "#E65000",
                      radius: "5",
                  },
                  circleTemplate
              );
              return am5.Bullet.new(root, {
                  sprite: graphics,
              });
          });
      }
      else {
          seriesC.bullets.clear();
      }
  });

Hope I explained myself. Thanks in advance.

Upvotes: 0

Views: 25

Answers (0)

Related Questions