Example XAxisScaleTimeExample not working
See original GitHub issueWhat 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:
- Created 4 years ago
- Reactions:1
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Change the date-fns import:
@garrett-gottlieb I already tried but I got another error. Maybe you know about this one ?