Skip to content

Commit bbbbac0

Browse files
committed
feat: add bar chart
1 parent 1f70149 commit bbbbac0

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/charts.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
2-
import type { ComposeOption, GridComponentOption } from 'echarts';
2+
import type { BarSeriesOption, ComposeOption, GridComponentOption } from 'echarts';
33
import {
4+
BarChart as EChartBarChart,
45
LineChart as EChartLineChart,
56
PieChart as EChartPieChart,
67
type LineSeriesOption,
@@ -92,6 +93,11 @@ function defineChart<T extends ComponentOption>(ext: EChartExt) {
9293
return ChartComponent;
9394
}
9495

96+
export const BarChart = /*#__PURE__*/ defineChart<BarSeriesOption | GridComponentOption>([
97+
EChartBarChart,
98+
GridComponent,
99+
]);
100+
95101
export const LineChart = /*#__PURE__*/ defineChart<LineSeriesOption | GridComponentOption>([
96102
EChartLineChart,
97103
GridComponent,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { CanvasRenderer, SVGRenderer } from 'echarts/renderers';
2-
export { LineChart, PieChart } from './charts.js';
2+
export { BarChart, LineChart, PieChart } from './charts.js';
33
export {
44
Dataset,
55
DataZoom,

stories/bar.stories.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { BarChart } from '@fanciers/echarts-react';
2+
import type { Meta, StoryObj } from '@storybook/react';
3+
4+
const meta = {
5+
title: 'Bar',
6+
} satisfies Meta;
7+
8+
export default meta;
9+
10+
export type Story = StoryObj<typeof meta>;
11+
12+
export const BarSimple: Story = {
13+
name: 'Basic Bar',
14+
render() {
15+
return (
16+
<BarChart
17+
style={{ width: 480, height: 300 }}
18+
xAxis={{
19+
type: 'category',
20+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
21+
}}
22+
yAxis={{ type: 'value' }}
23+
series={[
24+
{
25+
type: 'bar',
26+
data: [120, 200, 150, 80, 70, 110, 130],
27+
},
28+
]}
29+
/>
30+
);
31+
},
32+
};

0 commit comments

Comments
 (0)