-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added continuousLine prop to line chart #475
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,14 +3,22 @@ import Chart from '../chart/chart' | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
class LineChart extends Chart { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
createPaths({ data, x, y }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { curve } = this.props | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
const line = shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.line() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.x((d) => x(d.x)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.y((d) => y(d.y)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.defined((item) => typeof item.y === 'number') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.curve(curve)(data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { curve, continuousLine } = this.props | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
let line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (continuousLine) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
line = shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.line() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.x((d) => x(d.x)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.y((d) => y(d.y)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.curve(curve)(data.filter((item) => item.y)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
line = shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.line() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.x((d) => x(d.x)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.y((d) => y(d.y)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.defined((item) => typeof item.y === 'number') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.curve(curve)(data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+6
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this work?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, can you explain how can I use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, my suggestion above shows that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to implement the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you could provide a PR with your attempt and clearly stating what isn't working I might be able to help you 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you help me with this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I unfortunately don't have any time to assist outside of reviewing the PR. The user controls the data so I don't see why the user won't be able to filter the data? What exactly are you referring to in your example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JesperLekland For example, we want to show the week, and the data is only available for Monday and Thursday. Line Chart will not be able to connect Monday and Thursday. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not only |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
path: line, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react' | ||
import { LineChart, Grid } from 'react-native-svg-charts' | ||
|
||
class ContinuousLineLineChartExample extends React.PureComponent { | ||
render() { | ||
const data = [50, 10, 40, 95, null, -24, 85, 91, 35, 53, -53, null, 50, -20, -80] | ||
|
||
return ( | ||
<LineChart | ||
style={{ height: 200 }} | ||
data={data} | ||
svg={{ stroke: 'rgb(134, 65, 244)' }} | ||
contentInset={{ top: 20, bottom: 20 }} | ||
continuousLine | ||
> | ||
<Grid /> | ||
</LineChart> | ||
) | ||
} | ||
} | ||
|
||
export default ContinuousLineLineChartExample |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should look like below, since
data
is array ofline
.