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.

Creating a marker in line chart when the x axis is based on a time scale

See original GitHub issue

I am trying to create a x-axis marker (red line shown in the image) at the 12 PM point.

Screen Shot 2020-10-15 at 11 11 03 PM
<ResponsiveLine
      ...
      xScale={{
        type: 'time',
        format: '%H:%M',
        precision: 'minute',
        useUTC: false,
      }}
      xFormat="time:%H:%M"
      yScale={{
        min: 0,
        max: 80,
        type: 'linear',
      }}
      axisLeft={{
        ...
        format: (e) => e + '%',
      }}
      axisBottom={{
        ...
        format: '%I %p',
        tickValues: `every 3 hours`,
      }}
     markers={[
        {
          axis: 'y',
          value: 50,
          lineStyle: { stroke: '#fff', strokeWidth: 2 },
          legend: 'y marker',
          textStyle: {
            fill: '#fff',
            fontSize: 15,
          },
        },
        {
          axis: 'x',
          value: '12:00', // Here is the error, unable to translate on x-axis
          lineStyle: {
            stroke: '#ff0000',
            strokeWidth: 2,
            opacity: 1,
          },
          legend: 'x marker',
          textStyle: {
            fill: '#fff',
            fontSize: 15,
          },
        },
      ]}
     ...
/>

As you can see, the red marker is being rendered at 0 position rather than 12 PM. I feel the error is at value: '12:00' because the xScale cannot transform the string to a correct pixel value that would have rendered the red line at the right location.

I have tried passing the time in all possible formats but the red line still gets rendered at the 0 point. When inspecting the red line, I get the following error.

Error: <g> attribute transform: Expected number, "translate(undefined, 0)".

<g transform="translate(undefined, 0)">
<line x1="0" x2="0" y1="0" y2="220" stroke="#000000" stroke-width="1" style="stroke: rgb(255, 78, 94); stroke-width: 2; opacity: 1;">
</line>
<text transform="translate(14, 14) rotate(0)" text-anchor="start" dominant-baseline="central" style="fill: rgb(255, 255, 255); font-size: 15px;">x marker</text>
</g>

Any suggestion is appreciated! @plouc @wyze

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
arthuryeticommented, Dec 3, 2020

@rahul-rxr I think you should use new Date()

0reactions
stale[bot]commented, Mar 11, 2021

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create a Date or Time Chart in Excel | Pryor Learning
Open the Axis Options dropdown triangle. Make changes to the Bounds, Units, and so on to adjust the time-scale to display the chart...
Read more >
Change data markers in a line, scatter, or radar chart
Click Marker Options, and then under Marker Type, make sure that Built-in is selected. In the Type box, select the marker type that...
Read more >
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 >
Create a Date Based Axis or Text Based Axis Line Chart
When you create a chart, there are usually many option you have to fine tune the way information is show. One of those...
Read more >
How To Create A Line Graph In Excel (With Multiple Lines)
In this tutorial, I will show you how to create a line graph in Excel. I will firstly show you how to create...
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