Loading...
Loading...
Compare original and translation side by side
Note: This library was archived in June 2025. While still functional, Shopify recommends reaching out to support for migration assistance if building new features.
注意:本库已于2025年6月归档。虽然仍可正常使用,但如果你要构建新功能,Shopify建议联系支持团队获取迁移协助。
npm install @shopify/polaris-viznpm install @shopify/polaris-vizundefinedundefinedPolarisVizProviderimport { PolarisVizProvider } from '@shopify/polaris-viz';
import '@shopify/polaris-viz/build/esm/styles.css';
function App() {
return (
<PolarisVizProvider>
{/* Your app */}
</PolarisVizProvider>
);
}PolarisVizProviderimport { PolarisVizProvider } from '@shopify/polaris-viz';
import '@shopify/polaris-viz/build/esm/styles.css';
function App() {
return (
<PolarisVizProvider>
{/* Your app */}
</PolarisVizProvider>
);
}| Component | Use Case | Max Data Points |
|---|---|---|
| Comparing discrete categories | ~6 categories |
| Simple horizontal bars | ~6 categories |
| Trends over time | 30+ points |
| Compact inline trends | Any |
| Part-to-whole relationships | ~6 segments |
| Cumulative trends | 30+ points |
| Conversion funnels | ~6 stages |
| 组件 | 适用场景 | 最大数据量 |
|---|---|---|
| 离散类别对比 | 约6个类别 |
| 简单横向柱状图 | 约6个类别 |
| 随时间变化的趋势 | 30个以上数据点 |
| 紧凑型行内趋势图 | 无限制 |
| 部分与整体的关系 | 约6个分段 |
| 累积趋势 | 30个以上数据点 |
| 转化漏斗 | 约6个阶段 |
import { BarChart } from '@shopify/polaris-viz';
const data = [
{
name: 'Sales',
data: [
{ key: 'Monday', value: 150 },
{ key: 'Tuesday', value: 200 },
{ key: 'Wednesday', value: 175 },
],
},
];
<BarChart data={data} />import { BarChart } from '@shopify/polaris-viz';
const data = [
{
name: 'Sales',
data: [
{ key: 'Monday', value: 150 },
{ key: 'Tuesday', value: 200 },
{ key: 'Wednesday', value: 175 },
],
},
];
<BarChart data={data} />import { LineChart } from '@shopify/polaris-viz';
const data = [
{
name: 'Orders',
data: [
{ key: 'Jan', value: 100 },
{ key: 'Feb', value: 150 },
{ key: 'Mar', value: 200 },
],
},
];
<LineChart data={data} />import { LineChart } from '@shopify/polaris-viz';
const data = [
{
name: 'Orders',
data: [
{ key: 'Jan', value: 100 },
{ key: 'Feb', value: 150 },
{ key: 'Mar', value: 200 },
],
},
];
<LineChart data={data} />import { DonutChart } from '@shopify/polaris-viz';
const data = [
{ name: 'Direct', data: [{ key: 'Direct', value: 200 }] },
{ name: 'Social', data: [{ key: 'Social', value: 150 }] },
{ name: 'Email', data: [{ key: 'Email', value: 100 }] },
];
<DonutChart data={data} />import { DonutChart } from '@shopify/polaris-viz';
const data = [
{ name: 'Direct', data: [{ key: 'Direct', value: 200 }] },
{ name: 'Social', data: [{ key: 'Social', value: 150 }] },
{ name: 'Email', data: [{ key: 'Email', value: 100 }] },
];
<DonutChart data={data} />import { SparkLineChart } from '@shopify/polaris-viz';
const data = [
{
data: [
{ key: 0, value: 100 },
{ key: 1, value: 150 },
{ key: 2, value: 120 },
{ key: 3, value: 180 },
],
},
];
<SparkLineChart data={data} />import { SparkLineChart } from '@shopify/polaris-viz';
const data = [
{
data: [
{ key: 0, value: 100 },
{ key: 1, value: 150 },
{ key: 2, value: 120 },
{ key: 3, value: 180 },
],
},
];
<SparkLineChart data={data} />DataSeriesinterface DataPoint {
key: string | number; // X-axis value or category
value: number | null; // Y-axis value (null for gaps)
}
interface DataSeries {
name: string; // Series label
data: DataPoint[]; // Array of data points
color?: string; // Optional color override
isComparison?: boolean; // Mark as comparison data (renders grey)
}DataSeriesinterface DataPoint {
key: string | number; // X轴数值或分类
value: number | null; // Y轴数值(空值用null表示)
}
interface DataSeries {
name: string; // 系列标签
data: DataPoint[]; // 数据点数组
color?: string; // 可选自定义颜色
isComparison?: boolean; // 标记为对比数据(渲染为灰色)
}theme// Use built-in themes
<BarChart data={data} theme="Light" />
<BarChart data={data} theme="Dark" />
// Or define custom themes in provider
<PolarisVizProvider
themes={{
MyBrand: {
chartContainer: { backgroundColor: '#f9f9f9' },
seriesColors: { upToEight: ['#5c6ac4', '#47c1bf'] },
},
}}
>
<BarChart data={data} theme="MyBrand" />
</PolarisVizProvider>theme// 使用内置主题
<BarChart data={data} theme="Light" />
<BarChart data={data} theme="Dark" />
// 也可以在Provider中定义自定义主题
<PolarisVizProvider
themes={{
MyBrand: {
chartContainer: { backgroundColor: '#f9f9f9' },
seriesColors: { upToEight: ['#5c6ac4', '#47c1bf'] },
},
}}
>
<BarChart data={data} theme="MyBrand" />
</PolarisVizProvider>| Prop | Type | Description |
|---|---|---|
| | Chart data |
| | Theme name |
| | Enable/disable animations |
| | Show legend |
| | X-axis configuration |
| | Y-axis configuration |
| | Text when no data |
| 属性 | 类型 | 说明 |
|---|---|---|
| | 图表数据 |
| | 主题名称 |
| | 开/关动画效果 |
| | 是否显示图例 |
| | X轴配置 |
| | Y轴配置 |
| | 无数据时的提示文字 |