You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+91-40Lines changed: 91 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,13 +37,13 @@ yarn add react-native-webview
37
37
## Quick Start
38
38
39
39
```tsx
40
-
importReact, { useState, useMemo } from'react';
41
-
import { View } from'react-native';
42
-
importChartfrom'react-native-d3-chart';
40
+
importReact, { useState, useMemo } from'react'
41
+
import { View } from'react-native'
42
+
importChartfrom'react-native-d3-chart'
43
43
44
44
exportdefaultfunction App() {
45
-
const [width, setWidth] =useState(0);
46
-
const height =width*0.6;// 16:10 aspect ratio
45
+
const [width, setWidth] =useState(0)
46
+
const height =width*0.6// 16:10 aspect ratio
47
47
48
48
// Generate some sample data
49
49
const datasets =useMemo(
@@ -61,7 +61,7 @@ export default function App() {
61
61
},
62
62
],
63
63
[]
64
-
);
64
+
)
65
65
66
66
const timeDomain =useMemo(
67
67
() => ({
@@ -70,7 +70,7 @@ export default function App() {
70
70
end: Date.now(),
71
71
}),
72
72
[]
73
-
);
73
+
)
74
74
75
75
const colors = {
76
76
background: '#fff',
@@ -79,7 +79,7 @@ export default function App() {
79
79
cursorStroke: '#0ff',
80
80
highlightLabel: '#000',
81
81
highlightTime: '#444',
82
-
};
82
+
}
83
83
84
84
return (
85
85
<View
@@ -95,7 +95,7 @@ export default function App() {
95
95
noDataString="No data available"
96
96
/>
97
97
</View>
98
-
);
98
+
)
99
99
}
100
100
```
101
101
@@ -126,62 +126,74 @@ export default function App() {
126
126
127
127
```typescript
128
128
typeDataset= {
129
-
measurementName:string; // Display name for this data series
130
-
color:string; // Hex color for the line and labels
131
-
points:Point[]; // Array of data points
132
-
unit:string; // Unit symbol (e.g., '°C', 'kg', 'm/s')
133
-
decimals:number; // Number of decimal places to show
134
-
minDeltaY?:number; // Minimum Y-axis change to show, limit Y-zoom
135
-
decimalSeparator?:'.'|','; // Decimal separator
129
+
measurementName:string// Display name for this data series
130
+
color:string|ThresholdColor// Hex color for the line, or threshold-based coloring
131
+
points:Point[] // Array of data points
132
+
unit:string// Unit symbol (e.g., '°C', 'kg', 'm/s')
133
+
decimals:number// Number of decimal places to show
134
+
minDeltaY?:number// Minimum Y-axis change to show, limit Y-zoom
135
+
areaColor?:string// Optional area fill color (defaults to base color)
136
+
axisColor?:string// Optional Y-axis text color (defaults to base color)
137
+
decimalSeparator?:'.'|','// Decimal separator
136
138
domain?: {
137
139
// Custom Y-axis range
138
-
bottom:number;
139
-
top:number;
140
-
};
141
-
};
140
+
bottom:number
141
+
top:number
142
+
}
143
+
}
144
+
145
+
typeThresholdColor= {
146
+
type:'thresholds'
147
+
baseColor:string// Default color for values below all thresholds
148
+
gradientBlur:number// Gradient transition distance around thresholds
149
+
thresholds:Array<{
150
+
value:number// Threshold value
151
+
color:string// Color to use above this value
152
+
}> // Should be sorted by value descending
153
+
}
142
154
```
143
155
144
156
#### Point
145
157
146
158
```typescript
147
159
typePoint= {
148
-
timestamp:number;// Unix timestamp in milliseconds
149
-
value:number|null;// Data value (null for gaps)
150
-
};
160
+
timestamp:number// Unix timestamp in milliseconds
161
+
value:number|null// Data value (null for gaps)
162
+
}
151
163
```
152
164
153
165
#### TimeDomain
154
166
155
167
```typescript
156
168
typeTimeDomain= {
157
-
type:string;// Domain type (e.g., 'hour', 'day', 'week')
158
-
start:number;// Start timestamp (ms)
159
-
end:number;// End timestamp (ms)
160
-
};
169
+
type:string// Domain type (e.g., 'hour', 'day', 'week')
170
+
start:number// Start timestamp (ms)
171
+
end:number// End timestamp (ms)
172
+
}
161
173
```
162
174
163
175
#### ChartColors
164
176
165
177
```typescript
166
178
typeChartColors= {
167
-
background:string;// Chart background color
168
-
highlightLine:string;// Crosshair line color
169
-
border:string;// Chart border color
170
-
highlightLabel:string;// Value label text color
171
-
highlightTime:string;// Time label text color
172
-
cursorStroke:string;// Cursor/crosshair circle color
173
-
};
179
+
background:string// Chart background color
180
+
highlightLine:string// Crosshair line color
181
+
border:string// Chart border color
182
+
highlightLabel:string// Value label text color
183
+
highlightTime:string// Time label text color
184
+
cursorStroke:string// Cursor/crosshair circle color
185
+
}
174
186
```
175
187
176
188
#### CalendarStrings
177
189
178
190
```typescript
179
191
typeCalendarStrings= {
180
-
days:string[];// Full day names (Sunday first)
181
-
shortDays:string[];// Short day names (Sun first)
182
-
months:string[];// Full month names (January first)
183
-
shortMonths:string[];// Short month names (Jan first)
184
-
};
192
+
days:string[] // Full day names (Sunday first)
193
+
shortDays:string[] // Short day names (Sun first)
194
+
months:string[] // Full month names (January first)
195
+
shortMonths:string[] // Short month names (Jan first)
196
+
}
185
197
```
186
198
187
199
## Advanced Usage
@@ -204,9 +216,48 @@ const datasets = [
204
216
decimals: 0,
205
217
points: humidityData,
206
218
},
207
-
];
219
+
]
208
220
```
209
221
222
+
### Threshold-Based Colors
223
+
224
+
Create dynamic line colors that change based on data values using threshold configurations. This is perfect for showing status indicators, alerts, or different states in your data:
225
+
226
+
```tsx
227
+
const datasetWithThresholds = {
228
+
measurementName: 'Server Load',
229
+
unit: '%',
230
+
decimals: 0,
231
+
areaColor: '#e78e96', // Optional: custom area fill color
232
+
color: {
233
+
type: 'thresholds',
234
+
baseColor: '#089851', // Green for values below all thresholds (low load)
235
+
gradientBlur: 50, // Smooth transition distance around thresholds
236
+
thresholds: [
237
+
{ value: 85, color: '#CF1E2E' }, // Red for values >= 85% (critical)
0 commit comments