GraphicRenderer
GraphicRenderer 根据 Graphic Walker 规格渲染预配置的图表。它不带完整的编辑界面 — 用户可以查看和交互图表,但不能修改字段编码。
import { GraphicRenderer } from '@kanaries/graphic-walker';使用场景
| 组件 | 适用场景 |
|---|---|
GraphicWalker | 需要完整的拖拽式探索界面 |
GraphicRenderer | 展示保存的图表,保留工具栏控件 |
PureRenderer | 最简化的只读图表,无 UI 控件 |
属性
GraphicRenderer 接受与 GraphicWalker 相同的所有属性,另外还支持:
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
containerClassName | string | undefined | 图表容器的 CSS 类名。 |
containerStyle | React.CSSProperties | undefined | 图表容器的内联样式。 |
overrideSize | { mode: 'auto' | 'fixed' | 'full'; width: number; height: number } | undefined | 覆盖规格中的图表大小。 |
所有来自 GraphicWalker 的数据、外观、国际化和 ref 属性在此同样适用。
示例
import { GraphicRenderer } from '@kanaries/graphic-walker';
import type { IChart } from '@kanaries/graphic-walker';
const savedCharts: IChart[] = [
{
visId: 'chart-1',
name: 'Monthly Revenue',
encodings: {
dimensions: [],
measures: [],
rows: [{ fid: 'revenue', name: 'Revenue', analyticType: 'measure', semanticType: 'quantitative' }],
columns: [{ fid: 'month', name: 'Month', analyticType: 'dimension', semanticType: 'temporal' }],
color: [],
opacity: [],
size: [],
shape: [],
theta: [],
radius: [],
longitude: [],
latitude: [],
geoId: [],
details: [],
filters: [],
text: [],
},
config: {
defaultAggregated: true,
geoms: ['line'],
coordSystem: 'generic',
limit: -1,
},
layout: {
showTableSummary: false,
stack: 'none',
showActions: false,
interactiveScale: true,
zeroScale: true,
size: { mode: 'auto', width: 800, height: 400 },
format: {},
resolve: {},
},
},
];
function Dashboard() {
return (
<GraphicRenderer
data={data}
fields={fields}
chart={savedCharts}
appearance="media"
/>
);
}固定大小
<GraphicRenderer
data={data}
fields={fields}
chart={savedCharts}
overrideSize={{ mode: 'fixed', width: 600, height: 400 }}
/>