Merge pull request #13 from Abhinandan-Kushwaha/development

Added textShiftX and textShiftY props to LineChart
This commit is contained in:
Abhinandan Kushwaha 2021-08-13 20:09:54 +05:30 committed by GitHub
commit 8cb6d7ea02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 33 deletions

87
App.js
View File

@ -71,26 +71,32 @@ const App = () => {
}, },
]; ];
// const barData1 = [ const barData1 = [
// {value: 250, label: 'M'}, {value: 250, label: 'M'},
// {value: 500, label: 'T', frontColor: '#177AD5'}, {value: 500, label: 'T', frontColor: '#177AD5'},
// {value: 745, label: 'W', frontColor: '#177AD5'}, {value: 745, label: 'W', frontColor: '#177AD5'},
// {value: 320, label: 'T'}, {value: 320, label: 'T'},
// {value: 600, label: 'F', frontColor: '#177AD5'}, {value: 600, label: 'F', frontColor: '#177AD5'},
// {value: 256, label: 'S'}, {value: 256, label: 'S'},
// {value: 300, label: 'S'}, {value: 300, label: 'S'},
// ]; ];
// const lineData1 = [ const lineData1 = [
// {value: 0}, {value: 0, dataPointText: '0'},
// {value: 20}, {value: 20, dataPointText: '20'},
// {value: 18}, {value: 18, dataPointText: '18'},
// {value: 40}, {value: 40, dataPointText: '40'},
// {value: 36}, {value: 36, dataPointText: '36'},
// {value: 60}, {value: 60, dataPointText: '60'},
// {value: 54}, {value: 54, dataPointText: '54'},
// {value: 85}, {value: 85, dataPointText: '85'},
// ]; ];
const ldata = [
{value: 15, label: '15'},
{value: 30, label: '30'},
{value: 26, label: '26'},
{value: 40, label: '40'},
];
// const MyComponent = () => { // const MyComponent = () => {
// return ( // return (
@ -107,14 +113,28 @@ const App = () => {
{value: 250, label: 'Apr', frontColor: '#4ADDBA'}, {value: 250, label: 'Apr', frontColor: '#4ADDBA'},
{value: 320, label: 'May', frontColor: '#91E3E3'}, {value: 320, label: 'May', frontColor: '#91E3E3'},
]; ];
const lineData = [
{value: 0},
{value: 20},
{value: 18},
{value: 40},
{value: 36},
{value: 60},
{value: 54},
{value: 85},
];
return ( return (
<View <View
style={{ style={{
marginTop: 200, marginTop: 200,
paddingVertical: 50, paddingVertical: 50,
backgroundColor: '#1A3461',
}}> }}>
{/* <LineChart data={ldata} /> */}
{/* <BarChart {/* <BarChart
data={data} data={data}
horizontal
showGradient showGradient
cappedBars cappedBars
capColor={'rgba(78, 0, 142)'} capColor={'rgba(78, 0, 142)'}
@ -124,7 +144,7 @@ const App = () => {
frontColor={'rgba(219, 182, 249,0.2)'} frontColor={'rgba(219, 182, 249,0.2)'}
/> */} /> */}
<BarChart {/* <BarChart
width={340} width={340}
rotateLabel rotateLabel
barWidth={12} barWidth={12}
@ -132,16 +152,16 @@ const App = () => {
noOfSections={4} noOfSections={4}
barBorderRadius={6} barBorderRadius={6}
stackData={stackData} stackData={stackData}
/> /> */}
{/* <BarChart {/* <BarChart
frontColor={'#177AD5'} frontColor={'#177AD5'}
barWidth={22} barWidth={22}
data={[{value: 15}, {value: 30}, {value: 26}, {value: 40}]} data={[{value: 15}, {value: 30}, {value: 26}, {value: 40}]}
/> */} /> */}
{/* <LineChart {/* <LineChart
curved
initialSpacing={0} initialSpacing={0}
data={lineData1} data={lineData}
spacing={30} spacing={30}
hideDataPoints hideDataPoints
thickness={5} thickness={5}
@ -153,9 +173,30 @@ const App = () => {
xAxisColor="#0BA5A4" xAxisColor="#0BA5A4"
color="#0BA5A4" color="#0BA5A4"
/> */} /> */}
<LineChart
initialSpacing={0}
data={lineData1}
spacing={40}
textShiftY={-10}
textShiftX={-5}
// hideDataPoints
textColor="yellow"
textFontSize={12}
thickness={5}
hideRules
hideYAxisText
yAxisColor="#0BA5A4"
showVerticalLines
verticalLinesColor="rgba(14,164,164,0.5)"
xAxisColor="#0BA5A4"
color="#0BA5A4"
/>
{/* <View style={{marginLeft: 20}}> {/* <View style={{marginLeft: 20}}>
<BarChart <BarChart
barWidth={22} barWidth={22}
horizontal
yAxisAtTop
// spacing={16} // spacing={16}
// height={260} // height={260}
noOfSections={3} noOfSections={3}

View File

@ -4,7 +4,7 @@ The most complete library for Bar, Line, Area, Pie, and Donut charts in React Na
### Yet another chart library? Why? ### Yet another chart library? Why?
**_To bring Life to your data_** **_To bring Life to your data_**
1. Plenty of features with minimal code 1. Plenty of features with minimal code
2. Apply animations to your charts on load and on value change, just by adding a prop 2. Apply animations to your charts on load and on value change, just by adding a prop
@ -37,7 +37,7 @@ For Pie chart and Donut chart, these additional packages should be installed-
npm i react-native-canvas react-native-webview npm i react-native-canvas react-native-webview
``` ```
You can omit the above packages if you don't intend to use Pie chart or Donuut chart. You can omit the above packages if you don't intend to use Pie chart or Donut chart.
For iOS- For iOS-
@ -46,6 +46,7 @@ cd ios && pod install
``` ```
# Docs # Docs
[Documentation and gallery](https://gifted-charts.web.app/) [Documentation and gallery](https://gifted-charts.web.app/)
## Usage ## Usage

View File

@ -133,6 +133,10 @@ If you are adding showDataPoint to an item, you must set hideDataPoints prop to
| dataPointsRadius2 | number | Radius of data points for the second dataset (when data points' shape is circular) | 3 | | dataPointsRadius2 | number | Radius of data points for the second dataset (when data points' shape is circular) | 3 |
| dataPointsColor2 | ColorValue | Color of data points for the second dataset | blue | | dataPointsColor2 | ColorValue | Color of data points for the second dataset | blue |
| dataPointsShape2 | string | Shape of data points for the second dataset (_'rectangular'_ or _'circular'_) | 'circular' | | dataPointsShape2 | string | Shape of data points for the second dataset (_'rectangular'_ or _'circular'_) | 'circular' |
| textColor | ColorValue | Color of the dataPointText | 'black' |
| textFontSize | number | Font size of the dataPointText | \_ |
| textShiftX | number | To shift the dataPointText text horizontally | 0 |
| textShiftY | number | To shift the dataPointText text vertically | 0 |
--- ---

View File

@ -119,6 +119,8 @@ type propTypes = {
textFontSize2?: number; textFontSize2?: number;
textColor2?: string; textColor2?: string;
hideOrigin?: Boolean; hideOrigin?: Boolean;
textShiftX?: number;
textShiftY?: number;
}; };
type itemType = { type itemType = {
value?: number; value?: number;
@ -712,14 +714,14 @@ export const LineChart = (props: propTypes) => {
initialSpacing - initialSpacing -
(item.dataPointWidth || 2) + (item.dataPointWidth || 2) +
spacing * index + spacing * index +
(item.textShiftX || 0) (item.textShiftX || props.textShiftX || 0)
} }
y={ y={
containerHeight - containerHeight -
(item.dataPointHeight || 2) / 2 + (item.dataPointHeight || 2) / 2 +
10 - 10 -
(item.value * containerHeight) / maxValue + (item.value * containerHeight) / maxValue +
(item.textShiftY || 0) (item.textShiftY || props.textShiftY || 0)
}> }>
{item.dataPointText} {item.dataPointText}
</CanvasText> </CanvasText>
@ -751,14 +753,14 @@ export const LineChart = (props: propTypes) => {
initialSpacing - initialSpacing -
(item.dataPointWidth || 2) + (item.dataPointWidth || 2) +
spacing * index + spacing * index +
(item.textShiftX || 0) (item.textShiftX || props.textShiftX || 0)
} }
y={ y={
containerHeight - containerHeight -
(item.dataPointHeight || 2) / 2 + (item.dataPointHeight || 2) / 2 +
10 - 10 -
(item.value * containerHeight) / maxValue + (item.value * containerHeight) / maxValue +
(item.textShiftY || 0) (item.textShiftY || props.textShiftY || 0)
}> }>
{item.dataPointText} {item.dataPointText}
</CanvasText> </CanvasText>
@ -806,14 +808,14 @@ export const LineChart = (props: propTypes) => {
initialSpacing - initialSpacing -
dataPointsWidth + dataPointsWidth +
spacing * index + spacing * index +
(item.textShiftX || 0) (item.textShiftX || props.textShiftX || props.textShiftX || 0)
} }
y={ y={
containerHeight - containerHeight -
dataPointsHeight / 2 + dataPointsHeight / 2 +
10 - 10 -
(item.value * containerHeight) / maxValue + (item.value * containerHeight) / maxValue +
(item.textShiftY || 0) (item.textShiftY || props.textShiftY || 0)
}> }>
{item.dataPointText} {item.dataPointText}
</CanvasText> </CanvasText>
@ -839,14 +841,14 @@ export const LineChart = (props: propTypes) => {
initialSpacing - initialSpacing -
dataPointsWidth + dataPointsWidth +
spacing * index + spacing * index +
(item.textShiftX || 0) (item.textShiftX || props.textShiftX || 0)
} }
y={ y={
containerHeight - containerHeight -
dataPointsHeight / 2 + dataPointsHeight / 2 +
10 - 10 -
(item.value * containerHeight) / maxValue + (item.value * containerHeight) / maxValue +
(item.textShiftY || 0) (item.textShiftY || props.textShiftY || 0)
}> }>
{item.dataPointText} {item.dataPointText}
</CanvasText> </CanvasText>