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.

Example XAxisScaleTimeExample not working

See original GitHub issue

What is the problem?

Error

TypeError: undefined is not an object (evaluating '_dateFns.default.setHours')

When trying XAxisScaleTimeExample.

What platform?

  • iOS
  • Android

react-native version: 0.61.5 react-native-svg-charts version: 5.3.0 react-native-svg version: 11.0.1

Code to reproduce

import React from "react";
import { AreaChart, XAxis, Grid } from "react-native-svg-charts";
import { View } from "react-native";
import * as scale from "d3-scale";
import * as shape from "d3-shape";
import dateFns from "date-fns";

const data = [
  {
    value: 50,
    date: dateFns.setHours(new Date(2018, 0, 0), 6)
  },
  {
    value: 10,
    date: dateFns.setHours(new Date(2018, 0, 0), 9)
  },
  {
    value: 150,
    date: dateFns.setHours(new Date(2018, 0, 0), 15)
  },
  {
    value: 10,
    date: dateFns.setHours(new Date(2018, 0, 0), 18)
  },
  {
    value: 100,
    date: dateFns.setHours(new Date(2018, 0, 0), 21)
  },
  {
    value: 20,
    date: dateFns.setHours(new Date(2018, 0, 0), 24)
  }
];

export default function App() {
  return (
    <View style={{ height: 200, padding: 20 }}>
      <AreaChart
        style={{ flex: 1 }}
        data={data}
        yAccessor={({ item }) => item.value}
        xAccessor={({ item }) => item.date}
        xScale={scale.scaleTime}
        contentInset={{ top: 10, bottom: 10 }}
        svg={{ fill: "rgba(134, 65, 244, 0.5)" }}
        curve={shape.curveLinear}
      >
        <Grid />
      </AreaChart>
      <XAxis
        data={data}
        svg={{
          fill: "black",
          fontSize: 8,
          fontWeight: "bold",
          rotation: 20,
          originY: 30,
          y: 5
        }}
        xAccessor={({ item }) => item.date}
        scale={scale.scaleTime}
        numberOfTicks={6}
        style={{ marginHorizontal: -15, height: 20 }}
        contentInset={{ left: 10, right: 25 }}
        formatLabel={value => dateFns.format(value, "HH:mm")}
      />
    </View>
  );
}

Stacktrace (if crash)

TypeError: undefined is not an object (evaluating '_dateFns.default.setHours')
<global>
    App.js:9:2
loadModuleImplementation
    require.js:322:6
<global>
    AppEntry.js:5
loadModuleImplementation
    require.js:322:6
guardedLoadModule
    require.js:201:45
global code
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:166617:4

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

3reactions
peterkuipercommented, Feb 26, 2020

Change the date-fns import:

import * as dateFns from 'date-fns'
0reactions
BBenGitcommented, Apr 6, 2020

@garrett-gottlieb I already tried but I got another error. Maybe you know about this one ?

Change the date-fns import:

import * as dateFns from 'date-fns'

@peterkuiper I did the change but I got a new error …

Exception thrown while executing UI block: -[__NSCFNumber firstObject]: unrecognized selector sent to instance 0xec7dba9d817037c4

__53-[ABI36_0_0RCTUIManager flushUIBlocksWithCompletion:]_block_invoke
    ABI36_0_0RCTUIManager.m:1166
__53-[ABI36_0_0RCTUIManager flushUIBlocksWithCompletion:]_block_invoke.418
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
UIApplicationMain
main
start
0x0
Read more comments on GitHub >

github_iconTop Results From Across the Web

Formatting x-axis on d3js v5 doesn't work - Stack Overflow
You should use date & time scale for your x scale which is x = d3.scaleTime() . In ticks(10) , You might want...
Read more >
Time axis not working · Issue #876 · recharts/recharts - GitHub
I would like to activate scale="time" on that chart. I have tried several XAxis specifications, including the following: <XAxis dataKey="week"/> ...
Read more >
Top 5 d3-axis Code Examples - Snyk
To help you get started, we've selected a few d3-axis examples, based on popular ways it is used in public projects. ... Secure...
Read more >
Working with D3 Time Series Axes - Developer.com
In today's article, we'll learn how to use the scaleTime() function to present time series data on the x axis of a chart....
Read more >
Working With Dates - Using D3.js
As example, the specifier for a date of the form “April 1, 1970” is "%b %d, %Y”. ... scaleTime() .domain(domain) .range([25, 555]); var...
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