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

Date Axis group data property #1627

Closed
pratham3164 opened this issue Jul 24, 2024 · 6 comments
Closed

Date Axis group data property #1627

pratham3164 opened this issue Jul 24, 2024 · 6 comments

Comments

@pratham3164
Copy link

I am working on DateAxis and I have a huge data set to render in the chart. So I tried to group data it renders fewer records but it seems to render the last record in the group. Is it by design or I can change it to show other records as well like the first one in the group?

image

codepen for reference: https://codepen.io/ErPratham/pen/oNrzvGB

@martynasma
Copy link
Collaborator

It uses the value of the last data item in the group by default.

You can change it: https://www.amcharts.com/docs/v5/charts/xy-chart/axes/date-axis/#aggregation-function

@pratham3164
Copy link
Author

@martynasma even after using aggregation function. The datetime in the group is of the last data item . is it possible to show the datetime of the first or aggregated value in case of max min .

@zeroin
Copy link
Collaborator

zeroin commented Jul 26, 2024

Yes, the time is of the last grouped value. axis tooltip will show correct date:
https://codepen.io/team/amcharts/pen/gONwVXa

If you need correct date to be shown in tooltip, you will need to create adapter for labelText of a tooltip. This adapter should check what is current base interval and round or format date in a way you want, something like:

  tooltip.adapters.add("labelText", (labelText)=>{
    var baseInterval = xAxis0.getPrivate("baseInterval")
    
    if(baseInterval.timeUnit == "day"){
      // round or format date 
    }
    else if(baseInterval == "hour"){
      
    }
    
    return labelText
  })

By the way you have some incorrect setup - baseInterval should be minute, not hour:

@pratham3164
Copy link
Author

pratham3164 commented Jul 26, 2024

the solution seems to work only for the series 0 and series 2 stills shows the same

tooltip.adapters.add("labelText", (labelText)=>{
  var baseInterval = xAxis0.getPrivate("baseInterval")
  if(baseInterval.timeUnit == "day"){
    labelText = "{name}:{date.formatDate('yyyy-MM-dd 00:00')} : {valueY}";
  }
  else if(baseInterval == "hour"){
  }
  return labelText
})

image

and how to get the timestamp of the first record to show up

@zeroin
Copy link
Collaborator

zeroin commented Jul 31, 2024

Did you add the same tooltip and adapter for the second series? It should be a different instance of a tooltip.

Copy link

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.

@github-actions github-actions bot added the stale label Aug 31, 2024
@zeroin zeroin closed this as completed Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants