Skip to content

Commit 5b633f3

Browse files
committed
feat: add some bar chart examples
1 parent 9de31d5 commit 5b633f3

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

stories/bar.stories.tsx

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Title,
1515
Toolbox,
1616
Tooltip,
17+
VisualMap,
1718
echarts,
1819
} from '@fanciers/echarts-react';
1920
import type { Meta, StoryObj } from '@storybook/react';
@@ -2347,3 +2348,177 @@ export const PolarRoundCap: Story = {
23472348
);
23482349
},
23492350
};
2351+
2352+
export const DataTransformSortBar: Story = {
2353+
name: 'Sort Data in Bar Chart',
2354+
render() {
2355+
return (
2356+
<BarChart
2357+
style={{ width: 480, height: 300 }}
2358+
xAxis={{ type: 'category', axisLabel: { interval: 0, rotate: 30 } }}
2359+
yAxis={{}}
2360+
series={{ type: 'bar', encode: { x: 'name', y: 'score' }, datasetIndex: 1 }}
2361+
>
2362+
<Dataset
2363+
dataset={[
2364+
{
2365+
dimensions: ['name', 'age', 'profession', 'score', 'date'],
2366+
source: [
2367+
['Hannah Krause', 41, 'Engineer', 314, '2011-02-12'],
2368+
['Zhao Qian', 20, 'Teacher', 351, '2011-03-01'],
2369+
['Jasmin Krause ', 52, 'Musician', 287, '2011-02-14'],
2370+
['Li Lei', 37, 'Teacher', 219, '2011-02-18'],
2371+
['Karle Neumann', 25, 'Engineer', 253, '2011-04-02'],
2372+
['Adrian Groß', 19, 'Teacher', '-', '2011-01-16'],
2373+
['Mia Neumann', 71, 'Engineer', 165, '2011-03-19'],
2374+
['Böhm Fuchs', 36, 'Musician', 318, '2011-02-24'],
2375+
['Han Meimei', 67, 'Engineer', 366, '2011-03-12'],
2376+
],
2377+
},
2378+
{ transform: { type: 'sort', config: { dimension: 'score', order: 'desc' } } },
2379+
]}
2380+
/>
2381+
</BarChart>
2382+
);
2383+
},
2384+
};
2385+
2386+
export const DatasetEncode0: Story = {
2387+
name: 'Simple Encode',
2388+
render() {
2389+
return (
2390+
<BarChart
2391+
style={{ width: 480, height: 300 }}
2392+
grid={{ containLabel: true }}
2393+
xAxis={{ name: 'amout' }}
2394+
yAxis={{ type: 'category' }}
2395+
series={[{ type: 'bar', encode: { x: 'amount', y: 'product' } }]}
2396+
>
2397+
<Dataset
2398+
dataset={{
2399+
source: [
2400+
['score', 'amount', 'product'],
2401+
[89.3, 58212, 'Matcha Latte'],
2402+
[57.1, 78254, 'Milk Tea'],
2403+
[74.4, 41032, 'Cheese Cocoa'],
2404+
[50.1, 12755, 'Cheese Brownie'],
2405+
[89.7, 20145, 'Matcha Cocoa'],
2406+
[68.1, 79146, 'Tea'],
2407+
[19.6, 91852, 'Orange Juice'],
2408+
[10.6, 101852, 'Lemon Juice'],
2409+
[32.7, 20112, 'Walnut Brownie'],
2410+
],
2411+
}}
2412+
/>
2413+
<VisualMap
2414+
visualMap={{
2415+
orient: 'horizontal',
2416+
left: 'center',
2417+
min: 10,
2418+
max: 100,
2419+
text: ['High Score', 'Low Score'],
2420+
dimension: 0,
2421+
inRange: { color: ['#65B581', '#FFCE34', '#FD665F'] },
2422+
}}
2423+
/>
2424+
</BarChart>
2425+
);
2426+
},
2427+
};
2428+
2429+
export const DatasetSeriesLayoutBy: Story = {
2430+
name: 'Series Layout By Column or Row',
2431+
render() {
2432+
return (
2433+
<BarChart
2434+
style={{ width: 480, height: 300 }}
2435+
grid={[{ bottom: '55%' }, { top: '55%' }]}
2436+
xAxis={[
2437+
{ type: 'category', gridIndex: 0 },
2438+
{ type: 'category', gridIndex: 1 },
2439+
]}
2440+
yAxis={[{ gridIndex: 0 }, { gridIndex: 1 }]}
2441+
series={[
2442+
// These series are in the first grid.
2443+
{ type: 'bar', seriesLayoutBy: 'row' },
2444+
{ type: 'bar', seriesLayoutBy: 'row' },
2445+
{ type: 'bar', seriesLayoutBy: 'row' },
2446+
// These series are in the second grid.
2447+
{ type: 'bar', xAxisIndex: 1, yAxisIndex: 1 },
2448+
{ type: 'bar', xAxisIndex: 1, yAxisIndex: 1 },
2449+
{ type: 'bar', xAxisIndex: 1, yAxisIndex: 1 },
2450+
{ type: 'bar', xAxisIndex: 1, yAxisIndex: 1 },
2451+
]}
2452+
>
2453+
<Legend legend={{}} />
2454+
<Tooltip tooltip={{}} />
2455+
<Dataset
2456+
dataset={{
2457+
source: [
2458+
['product', '2012', '2013', '2014', '2015'],
2459+
['Matcha Latte', 41.1, 30.4, 65.1, 53.3],
2460+
['Milk Tea', 86.5, 92.1, 85.7, 83.1],
2461+
['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4],
2462+
],
2463+
}}
2464+
/>
2465+
</BarChart>
2466+
);
2467+
},
2468+
};
2469+
2470+
export const DatasetSimple0: Story = {
2471+
name: 'Simple Example of Dataset',
2472+
render() {
2473+
return (
2474+
<BarChart
2475+
style={{ width: 480, height: 300 }}
2476+
xAxis={{ type: 'category' }}
2477+
yAxis={{}}
2478+
series={[{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]}
2479+
>
2480+
<Legend legend={{}} />
2481+
<Tooltip tooltip={{}} />
2482+
<Dataset
2483+
dataset={{
2484+
source: [
2485+
['product', '2015', '2016', '2017'],
2486+
['Matcha Latte', 43.3, 85.8, 93.7],
2487+
['Milk Tea', 83.1, 73.4, 55.1],
2488+
['Cheese Cocoa', 86.4, 65.2, 82.5],
2489+
['Walnut Brownie', 72.4, 53.9, 39.1],
2490+
],
2491+
}}
2492+
/>
2493+
</BarChart>
2494+
);
2495+
},
2496+
};
2497+
2498+
export const DatasetSimple1: Story = {
2499+
name: 'Dataset in Object Array',
2500+
render() {
2501+
return (
2502+
<BarChart
2503+
style={{ width: 480, height: 300 }}
2504+
xAxis={{ type: 'category' }}
2505+
yAxis={{}}
2506+
series={[{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]}
2507+
>
2508+
<Legend legend={{}} />
2509+
<Tooltip tooltip={{}} />
2510+
<Dataset
2511+
dataset={{
2512+
dimensions: ['product', '2015', '2016', '2017'],
2513+
source: [
2514+
{ product: 'Matcha Latte', 2015: 43.3, 2016: 85.8, 2017: 93.7 },
2515+
{ product: 'Milk Tea', 2015: 83.1, 2016: 73.4, 2017: 55.1 },
2516+
{ product: 'Cheese Cocoa', 2015: 86.4, 2016: 65.2, 2017: 82.5 },
2517+
{ product: 'Walnut Brownie', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
2518+
],
2519+
}}
2520+
/>
2521+
</BarChart>
2522+
);
2523+
},
2524+
};

0 commit comments

Comments
 (0)