question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question][Feature] How do you specify date format in tooltip?

See original GitHub issue

What problem does this feature solve?

Please see the following sample configuration:

option = {
  dataset: {
    source: [
      { date: '3022-03-01', count: 6 },
      { date: '3022-03-02', count: 3 },
      { date: '3022-03-03', count: 4 },
      { date: '3022-03-04', count: 6 },
      { date: '3022-03-05', count: 7 },
      { date: '3022-03-06', count: 2 },
      { date: '3022-03-07', count: 8 },
      { date: '3022-03-08', count: 6 },
      { date: '3022-03-09', count: 9 }
    ]
  },
  xAxis: {
    type: 'time',
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      type: 'line',
      name: 'Count'
    }
  ],
  tooltip: {
    trigger: 'axis'
  }
};

This results in the tooltip displaying the date with all zeros for time. Is there an easy way to format this as date-only? I know how to use a function for series.tooltip.valueFormatter for the other values, but I’m not sure how to do this for the x-axis since no series is defined for it.

image

What does the proposed API look like?

Perhaps a valueFormatter option added to xAxis.tooltip which accepts either a string or a function.

xAxis: {
    type: 'time',
    tooltip: {
        valueFormatter: 'yyyy-MM-dd'
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jkasperblcommented, Mar 21, 2022

Thanks @jiawulin001. That works, but I don’t think it’s a great solution for the following reasons:

  • You have to re-apply the default tooltip styling (with series color marker, etc.) for each value displayed
  • The valueFormatter functions for each series are now ignored and you have to use messier logic inside the main tooltip formatter

It would be much better if we could specify a valueFormatter for the independent axis so all other tooltip functionality works by default.

0reactions
jkasperblcommented, Jun 6, 2022

Thanks @Airkro, that one seems to do the trick! Much appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Format Date used in Tooltip - Tableau Community
Right Click on the date field which you created --> Default Properties --> Date Format --> Select the format which you want to...
Read more >
Localized date format in tooltip - amcharts - Stack Overflow
In my chart I'm displaying revenue data on a date axis by day. I would like to show the date in the tooltip...
Read more >
How to Format Date in the Tooltip Label?
Solved: Hello! How and where can I format the date that is displayed in the tooltip label? I need it to just say...
Read more >
How to Format Dates in the Tooltip in Chart.js - YouTube
Especially with the tooltip and having it shorten would be more suitable. Customizing the date in a format you want. To do this...
Read more >
How to format date/time data in Tooltips and along X-axis?
The information itself is shown fine but now I want to change the contence of the Tooltips of the data points and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found