Skip to content

Commit c9cbc99

Browse files
authored
Merge pull request #165 from objectstack-ai/copilot/fix-object-chart-components
2 parents 311e49f + f521519 commit c9cbc99

File tree

2 files changed

+104
-49
lines changed

2 files changed

+104
-49
lines changed

apps/site/app/components/InteractiveDemo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const pluginsLoading = typeof window !== 'undefined'
1616
import('@object-ui/plugin-charts'),
1717
import('@object-ui/plugin-kanban'),
1818
import('@object-ui/plugin-markdown'),
19-
// import('@object-ui/plugin-object'), // Temporarily disabled due to missing dependency
19+
import('@object-ui/plugin-object'),
2020
])
2121
: Promise.resolve([]);
2222

content/docs/plugins/plugin-charts.mdx

Lines changed: 103 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ npm install @object-ui/plugin-charts
3030
height: 300,
3131
color: "#8884d8"
3232
}}
33-
title="Bar Chart"
34-
description="Display data as vertical bars"
33+
title="Simple Bar Chart"
34+
description="Simple bar chart with basic API - type: 'bar-chart'"
3535
/>
3636

3737
<InteractiveDemo
3838
schema={{
39-
type: "line-chart",
39+
type: "chart",
40+
chartType: "line",
4041
data: [
4142
{ month: "Jan", revenue: 4000, expenses: 2400 },
4243
{ month: "Feb", revenue: 3000, expenses: 1398 },
@@ -45,35 +46,51 @@ npm install @object-ui/plugin-charts
4546
{ month: "May", revenue: 5000, expenses: 4800 },
4647
{ month: "Jun", revenue: 7000, expenses: 3800 }
4748
],
48-
lines: [
49-
{ dataKey: "revenue", stroke: "#8884d8", name: "Revenue" },
50-
{ dataKey: "expenses", stroke: "#82ca9d", name: "Expenses" }
51-
],
5249
xAxisKey: "month",
53-
height: 300
50+
series: [
51+
{ dataKey: "revenue" },
52+
{ dataKey: "expenses" }
53+
],
54+
config: {
55+
revenue: { label: "Revenue", color: "#8884d8" },
56+
expenses: { label: "Expenses", color: "#82ca9d" }
57+
}
5458
}}
55-
title="Multi-Line Chart"
56-
description="Compare multiple metrics over time"
59+
title="Advanced Line Chart"
60+
description="Advanced chart with multiple series - type: 'chart', chartType: 'line'"
5761
/>
5862

5963
<InteractiveDemo
6064
schema={{
61-
type: "pie-chart",
65+
type: "chart",
66+
chartType: "area",
6267
data: [
63-
{ name: "Desktop", value: 45, fill: "#8884d8" },
64-
{ name: "Mobile", value: 35, fill: "#82ca9d" },
65-
{ name: "Tablet", value: 20, fill: "#ffc658" }
68+
{ month: "Jan", users: 1200 },
69+
{ month: "Feb", users: 1450 },
70+
{ month: "Mar", users: 1680 },
71+
{ month: "Apr", users: 1920 },
72+
{ month: "May", users: 2100 },
73+
{ month: "Jun", users: 2350 }
6674
],
67-
dataKey: "value",
68-
nameKey: "name",
69-
height: 300
75+
xAxisKey: "month",
76+
series: [
77+
{ dataKey: "users" }
78+
],
79+
config: {
80+
users: { label: "Users", color: "#8884d8" }
81+
}
7082
}}
71-
title="Pie Chart"
72-
description="Show proportional data distribution"
83+
title="Area Chart"
84+
description="Show data trends with filled areas"
7385
/>
7486

7587
## Usage
7688

89+
The plugin provides two chart APIs:
90+
91+
1. **Simple Bar Chart** (`bar-chart`) - Simplified API for basic bar charts
92+
2. **Advanced Charts** (`chart`) - Full-featured API supporting multiple chart types (bar, line, area) and multiple data series
93+
7794
### Basic Usage
7895

7996
```tsx
@@ -96,7 +113,7 @@ const schema = {
96113

97114
## Features
98115

99-
- **Bar, line, area, and pie charts**
116+
- **Bar, line, and area charts**
100117
- **Responsive design**
101118
- **Customizable colors and styles**
102119
- **Lazy-loaded** (~540 KB loads only when rendered)
@@ -128,7 +145,11 @@ const schema = {
128145

129146
## Chart Types
130147

131-
### Bar Chart
148+
The plugin provides two different chart components:
149+
150+
### Simple Bar Chart (bar-chart)
151+
152+
For basic single-series bar charts, use the simplified `bar-chart` type:
132153

133154
```tsx
134155
const schema = {
@@ -145,50 +166,72 @@ const schema = {
145166
}
146167
```
147168

148-
### Line Chart
169+
### Advanced Charts (chart)
170+
171+
For multi-series charts or line/area charts, use the advanced `chart` type with the `chartType` property:
172+
173+
##### Bar Chart
149174

150175
```tsx
151176
const schema = {
152-
type: 'chart-line',
177+
type: 'chart',
178+
chartType: 'bar',
179+
data: [
180+
{ month: 'Jan', sales: 400, target: 350 },
181+
{ month: 'Feb', sales: 300, target: 400 },
182+
{ month: 'Mar', sales: 600, target: 550 }
183+
],
184+
xAxisKey: 'month',
185+
series: [
186+
{ dataKey: 'sales' },
187+
{ dataKey: 'target' }
188+
],
189+
config: {
190+
sales: { label: 'Sales', color: '#3b82f6' },
191+
target: { label: 'Target', color: '#10b981' }
192+
}
193+
}
194+
```
195+
196+
##### Line Chart
197+
198+
```tsx
199+
const schema = {
200+
type: 'chart',
201+
chartType: 'line',
153202
data: [
154203
{ date: '2024-01', users: 120 },
155204
{ date: '2024-02', users: 180 },
156205
{ date: '2024-03', users: 250 }
157206
],
158-
dataKey: 'users',
159207
xAxisKey: 'date',
160-
height: 350
208+
series: [
209+
{ dataKey: 'users' }
210+
],
211+
config: {
212+
users: { label: 'Users', color: '#8884d8' }
213+
}
161214
}
162215
```
163216

164-
### Area Chart
217+
###### Area Chart
165218

166219
```tsx
167220
const schema = {
168-
type: 'chart-area',
221+
type: 'chart',
222+
chartType: 'area',
169223
data: [
170224
{ time: '9:00', value: 20 },
171225
{ time: '10:00', value: 35 },
172226
{ time: '11:00', value: 45 }
173227
],
174-
dataKey: 'value',
175228
xAxisKey: 'time',
176-
color: '#10b981'
177-
}
178-
```
179-
180-
### Pie Chart
181-
182-
```tsx
183-
const schema = {
184-
type: 'chart-pie',
185-
data: [
186-
{ name: 'Desktop', value: 400 },
187-
{ name: 'Mobile', value: 300 },
188-
{ name: 'Tablet', value: 200 }
229+
series: [
230+
{ dataKey: 'value' }
189231
],
190-
dataKey: 'value',
191-
nameKey: 'name'
232+
config: {
233+
value: { label: 'Value', color: '#10b981' }
234+
}
192235
}
193236
```
194237

@@ -217,16 +260,23 @@ const revenueChart = {
217260

218261
```tsx
219262
const growthChart = {
220-
type: 'chart-line',
263+
type: 'chart',
264+
chartType: 'line',
221265
data: [
222266
{ month: 'Jan', users: 1200, active: 980 },
223267
{ month: 'Feb', users: 1450, active: 1150 },
224268
{ month: 'Mar', users: 1680, active: 1380 },
225269
{ month: 'Apr', users: 1920, active: 1620 }
226270
],
227-
dataKey: 'users',
228271
xAxisKey: 'month',
229-
height: 350
272+
series: [
273+
{ dataKey: 'users' },
274+
{ dataKey: 'active' }
275+
],
276+
config: {
277+
users: { label: 'Total Users', color: '#8884d8' },
278+
active: { label: 'Active Users', color: '#82ca9d' }
279+
}
230280
}
231281
```
232282

@@ -257,9 +307,14 @@ const schema = {
257307

258308
```tsx
259309
const schema = {
260-
type: 'chart-line',
310+
type: 'chart',
311+
chartType: 'line',
261312
data: metricsData,
262-
height: 500,
313+
xAxisKey: 'date',
314+
series: [{ dataKey: 'value' }],
315+
config: {
316+
value: { label: 'Metrics', color: '#8884d8' }
317+
},
263318
className: 'h-64 sm:h-96 lg:h-[500px]'
264319
}
265320
```

0 commit comments

Comments
 (0)