本页面展示 TaroViz 的各种交互式功能。您可以实时调整参数来体验图表的变化。
点击「刷新数据」按钮,模拟实时数据变化。
| 月份 | 销售额 | 利润 |
|---|---|---|
| 1月 | 120 | 80 |
| 2月 | 200 | 140 |
| 3月 | 150 | 100 |
| 4月 | 80 | 50 |
| 5月 | 70 | 40 |
| 6月 | 110 | 70 |
import { useState } from 'react'
import { LineChart } from '@agions/taroviz'
function DynamicDataChart() {
const [data, setData] = useState(initialData)
const refreshData = () => {
setData(prev => prev.map(item => ({
...item,
sales: Math.random() * 200 + 50,
profit: Math.random() * 150 + 30
})))
}
return (
<>
<LineChart data={data} />
<button onClick={refreshData}>刷新数据</button>
</>
)
}点击按钮切换不同主题风格。
import { LineChart } from '@agions/taroviz'
function ThemeChart() {
return (
<LineChart
theme="neon"
data={data}
/>
)
}
// 或使用主题对象
import { neonTheme } from '@agions/taroviz/themes'
function ThemeChart2() {
return (
<LineChart
theme={neonTheme}
data={data}
/>
)
}支持跟随系统或手动切换暗色模式。
import { LineChart } from '@agions/taroviz'
import { useTheme } from '@agions/taroviz/hooks'
function DarkModeChart() {
const { isDark, toggleDark } = useTheme()
return (
<>
<button onClick={toggleDark}>
{{ isDark ? '切换浅色' : '切换暗色' }}
</button>
<LineChart
:dark-mode="isDark"
data={data}
/>
</>
)
}控制图表动画的开关和配置。
import { LineChart } from '@agions/taroviz'
function AnimatedChart() {
return (
<LineChart
animation={{
enabled: true,
duration: 800,
easing: 'cubicOut'
}}
data={data}
/>
)
}图表自动适应容器大小变化。