Skip to content

Commit

Permalink
chore(charts): Add autoFit demo for Line
Browse files Browse the repository at this point in the history
  • Loading branch information
dengfuping committed Oct 8, 2023
1 parent ea73549 commit 0056ca6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/charts/src/Line/demo/auto-fit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useState, useEffect } from 'react';
import { Line } from '@oceanbase/charts';

export default () => {
const [data, setData] = useState([]);
const asyncFetch = () => {
fetch('https://gw.alipayobjects.com/os/bmw-prod/55424a73-7cb8-4f79-b60d-3ab627ac5698.json')
.then(response => response.json())
.then(json => setData(json))
.catch(error => {
console.log('fetch data failed', error);
});
};
useEffect(() => {
asyncFetch();
}, []);
const config = {
data,
xField: 'year',
yField: 'value',
seriesField: 'category',
xAxis: {
type: 'time',
},
yAxis: {
label: {
// 数值格式化为千分位
formatter: v => `${v}`.replace(/\d{1,3}(?=(\d{3})+$)/g, s => `${s},`),
},
},
style: {
height: '50vh',
},
};
return <Line {...config} />;
};
2 changes: 2 additions & 0 deletions packages/charts/src/Line/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ nav:

<code src="./demo/multiple.tsx" title="多折线图"></code>

<code src="./demo/auto-fit.tsx" title="自适应容器高度" description="调整浏览器窗口高度即可验证"></code>

<code src="./demo/tooltip-scrollable.tsx" title="Tooltip 可滚动" description="适用于 Tooltip 项较多、超出图表的场景,可通过 `tooltip.scrollable: true` 配置进行开启。"></code>

## API
Expand Down

0 comments on commit 0056ca6

Please sign in to comment.