UNPKG

8.12 kBTypeScriptView Raw
1import React from "react";
2import { Animated, TextInput, ViewStyle } from "react-native";
3import AbstractChart, { AbstractChartConfig, AbstractChartProps } from "../AbstractChart";
4import { ChartData, Dataset } from "../HelperTypes";
5export interface LineChartData extends ChartData {
6 legend?: string[];
7}
8export interface LineChartProps extends AbstractChartProps {
9 /**
10 * Data for the chart.
11 *
12 * Example from [docs](https://github.com/indiespirit/react-native-chart-kit#line-chart):
13 *
14 * ```javascript
15 * const data = {
16 * labels: ['January', 'February', 'March', 'April', 'May', 'June'],
17 * datasets: [{
18 * data: [ 20, 45, 28, 80, 99, 43 ],
19 * color: (opacity = 1) => `rgba(134, 65, 244, ${opacity})`, // optional
20 * strokeWidth: 2 // optional
21 * }],
22 * legend: ["Rainy Days", "Sunny Days", "Snowy Days"] // optional
23 * }
24 * ```
25 */
26 data: LineChartData;
27 /**
28 * Width of the chart, use 'Dimensions' library to get the width of your screen for responsive.
29 */
30 width: number;
31 /**
32 * Height of the chart.
33 */
34 height: number;
35 /**
36 * Show dots on the line - default: True.
37 */
38 withDots?: boolean;
39 /**
40 * Show shadow for line - default: True.
41 */
42 withShadow?: boolean;
43 /**
44 * Show inner dashed lines - default: True.
45 */
46 withScrollableDot?: boolean;
47 withInnerLines?: boolean;
48 /**
49 * Show outer dashed lines - default: True.
50 */
51 withOuterLines?: boolean;
52 /**
53 * Show vertical lines - default: True.
54 */
55 withVerticalLines?: boolean;
56 /**
57 * Show horizontal lines - default: True.
58 */
59 withHorizontalLines?: boolean;
60 /**
61 * Show vertical labels - default: True.
62 */
63 withVerticalLabels?: boolean;
64 /**
65 * Show horizontal labels - default: True.
66 */
67 withHorizontalLabels?: boolean;
68 /**
69 * Render charts from 0 not from the minimum value. - default: False.
70 */
71 fromZero?: boolean;
72 /**
73 * Prepend text to horizontal labels -- default: ''.
74 */
75 yAxisLabel?: string;
76 /**
77 * Append text to horizontal labels -- default: ''.
78 */
79 yAxisSuffix?: string;
80 /**
81 * Prepend text to vertical labels -- default: ''.
82 */
83 xAxisLabel?: string;
84 /**
85 * Configuration object for the chart, see example:
86 *
87 * ```javascript
88 * const chartConfig = {
89 * backgroundGradientFrom: "#1E2923",
90 * backgroundGradientFromOpacity: 0,
91 * backgroundGradientTo: "#08130D",
92 * backgroundGradientToOpacity: 0.5,
93 * color: (opacity = 1) => `rgba(26, 255, 146, ${opacity})`,
94 * labelColor: (opacity = 1) => `rgba(26, 255, 146, ${opacity})`,
95 * strokeWidth: 2, // optional, default 3
96 * barPercentage: 0.5
97 * };
98 * ```
99 */
100 chartConfig?: AbstractChartConfig;
101 /**
102 * Divide axis quantity by the input number -- default: 1.
103 */
104 yAxisInterval?: number;
105 /**
106 * Defines if chart is transparent
107 */
108 transparent?: boolean;
109 /**
110 * This function takes a [whole bunch](https://github.com/indiespirit/react-native-chart-kit/blob/master/src/line-chart.js#L266)
111 * of stuff and can render extra elements,
112 * such as data point info or additional markup.
113 */
114 decorator?: Function;
115 /**
116 * Callback that is called when a data point is clicked.
117 */
118 onDataPointClick?: (data: {
119 index: number;
120 value: number;
121 dataset: Dataset;
122 x: number;
123 y: number;
124 getColor: (opacity: number) => string;
125 }) => void;
126 /**
127 * Style of the container view of the chart.
128 */
129 style?: Partial<ViewStyle>;
130 /**
131 * Add this prop to make the line chart smooth and curvy.
132 *
133 * [Example](https://github.com/indiespirit/react-native-chart-kit#bezier-line-chart)
134 */
135 bezier?: boolean;
136 /**
137 * Defines the dot color function that is used to calculate colors of dots in a line chart.
138 * Takes `(dataPoint, dataPointIndex)` as arguments.
139 */
140 getDotColor?: (dataPoint: any, index: number) => string;
141 /**
142 * Renders additional content for dots in a line chart.
143 * Takes `({x, y, index})` as arguments.
144 */
145 renderDotContent?: (params: {
146 x: number;
147 y: number;
148 index: number;
149 }) => React.ReactNode;
150 /**
151 * Rotation angle of the horizontal labels - default 0 (degrees).
152 */
153 horizontalLabelRotation?: number;
154 /**
155 * Rotation angle of the vertical labels - default 0 (degrees).
156 */
157 verticalLabelRotation?: number;
158 /**
159 * Offset for Y axis labels.
160 */
161 yLabelsOffset?: number;
162 /**
163 * Offset for X axis labels.
164 */
165 xLabelsOffset?: number;
166 /**
167 * Array of indices of the data points you don't want to display.
168 */
169 hidePointsAtIndex?: number[];
170 /**
171 * This function change the format of the display value of the Y label.
172 * Takes the y value as argument and should return the desirable string.
173 */
174 formatYLabel?: (yValue: string) => string;
175 /**
176 * This function change the format of the display value of the X label.
177 * Takes the X value as argument and should return the desirable string.
178 */
179 formatXLabel?: (xValue: string) => string;
180 /**
181 * Provide props for a data point dot.
182 */
183 getDotProps?: (dataPoint: any, index: number) => object;
184 /**
185 * The number of horizontal lines
186 */
187 segments?: number;
188}
189declare type LineChartState = {
190 scrollableDotHorizontalOffset: Animated.Value;
191};
192declare class LineChart extends AbstractChart<LineChartProps, LineChartState> {
193 label: React.RefObject<TextInput>;
194 state: {
195 scrollableDotHorizontalOffset: Animated.Value;
196 };
197 getColor: (dataset: Dataset, opacity: number) => string;
198 getStrokeWidth: (dataset: Dataset) => number;
199 getDatas: (data: Dataset[]) => number[];
200 getPropsForDots: (x: any, i: number) => object;
201 renderDots: ({ data, width, height, paddingTop, paddingRight, onDataPointClick }: Pick<AbstractChartConfig, "data" | "height" | "width" | "paddingTop" | "paddingRight"> & {
202 onDataPointClick: LineChartProps["onDataPointClick"];
203 }) => React.ReactNode[];
204 renderScrollableDot: ({ data, width, height, paddingTop, paddingRight, scrollableDotHorizontalOffset, scrollableDotFill, scrollableDotStrokeColor, scrollableDotStrokeWidth, scrollableDotRadius, scrollableInfoViewStyle, scrollableInfoTextStyle, scrollableInfoTextDecorator, scrollableInfoSize, scrollableInfoOffset }: AbstractChartConfig & {
205 onDataPointClick: LineChartProps["onDataPointClick"];
206 scrollableDotHorizontalOffset: Animated.Value;
207 }) => any[];
208 renderShadow: ({ width, height, paddingRight, paddingTop, data, useColorFromDataset }: Pick<AbstractChartConfig, "data" | "height" | "width" | "paddingTop" | "paddingRight"> & {
209 useColorFromDataset: AbstractChartConfig["useShadowColorFromDataset"];
210 }) => JSX.Element[];
211 renderLine: ({ width, height, paddingRight, paddingTop, data, linejoinType }: Pick<AbstractChartConfig, "data" | "width" | "height" | "paddingRight" | "paddingTop" | "linejoinType">) => any[];
212 getBezierLinePoints: (dataset: Dataset, { width, height, paddingRight, paddingTop, data }: Pick<AbstractChartConfig, "width" | "height" | "paddingRight" | "paddingTop" | "data">) => string;
213 renderBezierLine: ({ data, width, height, paddingRight, paddingTop }: Pick<AbstractChartConfig, "data" | "width" | "height" | "paddingRight" | "paddingTop">) => JSX.Element[];
214 renderBezierShadow: ({ width, height, paddingRight, paddingTop, data, useColorFromDataset }: Pick<AbstractChartConfig, "data" | "height" | "width" | "paddingTop" | "paddingRight"> & {
215 useColorFromDataset: AbstractChartConfig["useShadowColorFromDataset"];
216 }) => JSX.Element[];
217 renderLegend: (width: any, legendOffset: any) => JSX.Element[];
218 render(): JSX.Element;
219}
220export default LineChart;
221//# sourceMappingURL=LineChart.d.ts.map
\No newline at end of file