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.

Correct ChartOptions types for a Line chart with Time scale

See original GitHub issue

Documentation Is:

  • Missing or needed
  • Confusing
  • Not Sure?

Please Explain in Detail…

I want to get the correct types for a Line chart which has Time scale. From documentation I found that I can pass "line" to the ChartOptions type.

const chartOptions = ChartOptions<'line'> = {
    scales: {
      x: {
        time: {
          unit: 'day'
        }
      }
    }
  }

But the problem is I can’t find any way to specify that I want to use the Time scale. As a result when I try to do the following

this.chartOptions.scales.x.time.unit = 'hour';

VSCode shows that,

Property 'time' does not exist on type '_DeepPartialObject<{ type: "linear"; } ...........

How can I use the proper types for Time scale on a Line chart so that I get the correct type checks? I could not find any documentation for this anywhere so any pointers is appreciated.

Your Proposal for Changes

Example

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
LeeLenaleeecommented, May 14, 2021

Chart.js is treeshakable so you will have to import and register the timescale, https://www.chartjs.org/docs/master/getting-started/integration.html#bundlers-webpack-rollup-etc

8reactions
ghostcommented, May 14, 2021

After adding this (time) correct format with Chart.js v3 , I am getting Error: “time” is not a registered scale. Any suggestions ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide to Line Charts | Tutorial by Chartio
Line charts are a fundamental chart type generally used to show change in values across time. Learn how to best use this chart...
Read more >
Time Cartesian Axis - Chart.js
Time Cartesian Axis. The time scale is used to display times and dates. Data are spread according to the amount of time between...
Read more >
How to Create a Date or Time Chart in Excel | Pryor Learning
To adjust how the x-axis time-scale is displayed: Click on the chart to open the Format Chart Area Pane. Click on Chart Options...
Read more >
Line Chart - Google Developers
Draws the chart inside an inline frame. (Note that on IE8, this option is ignored; all IE8 charts are drawn in i-frames.) Type:...
Read more >
Line chart options | Looker - Google Cloud
Charts with an Ordinal x-axis scale type. Click the Add Trend Line button to add trend lines in your chart. Click it as...
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