笛卡尔坐标
条形图
type: 'bar'水平条形图——使用相同渲染器和交换坐标轴的反向柱状图。所有柱状图选项都适用。
编辑右侧的JSON并按Run(或⌘/Ctrl + Enter)——数据、标题、类别和颜色全部实时更新。
实时
条形图
编辑 · JSON
数据格式
与柱状图相同
数据结构
传入图表的 JSON——可直接放进你的 series。
series: [
{ name: 'Adoption', data: [82, 61, 44, 38] }
]示例
import KatuCharts from 'katucharts.js';
KatuCharts.chart('container', {
chart: { type: 'bar' },
xAxis: { categories: ['React', 'Vue', 'Svelte', 'Angular'] },
series: [{ name: 'Adoption', data: [82, 61, 44, 38] }]
});类型特定选项
| 选项 | 描述 |
|---|---|
(所有柱状图选项) | groupPadding、stacking、colorByPoint等。 |
变体
堆叠条形
水平堆叠条形——相同的堆叠 API,交换了坐标轴。
KatuCharts.chart('container', {
chart: { type: 'bar' },
xAxis: { categories: ['Onboarding', '支持', 'Pricing', 'Docs'] },
plotOptions: { bar: { stacking: 'normal' } },
series: [
{ name: 'Agree', data: [62, 71, 44, 80] },
{ name: '中立', data: [22, 18, 31, 12] },
{ name: 'Disagree', data: [16, 11, 25, 8] }
]
});Common errors
- Why does my 条形图 chart render as a line chart?
- The chart type was not registered. KatuCharts logs "KatuCharts: unknown series type "<type>", falling back to line" and draws a line chart rather than throwing. Import the module the type belongs to — for example `import 'katucharts.js/bio';` — before creating the chart.
- Why do I get "Cannot read properties of null (reading 'appendChild')"?
- The container element does not exist when the chart is created. Create the chart after the element is in the DOM: in React that means inside useEffect, not during render.
- Why is the chart rendering with zero height?
- The container has no height. A div with no content collapses to zero. Give it a height in CSS, or pass `chart: { height: 400 }` in the options.
FAQ
- How do I create a 条形图 chart in JavaScript?
- Install with `npm install katucharts.js`, then call KatuCharts.chart(container, { chart: { type: 'bar' }, series: [...] }).
- Why does my 条形图 chart render as a line chart?
- The chart type was not registered. KatuCharts logs "KatuCharts: unknown series type "<type>", falling back to line" and draws a line chart rather than throwing. Import the module the type belongs to — for example `import 'katucharts.js/bio';` — before creating the chart.
- Why do I get "Cannot read properties of null (reading 'appendChild')"?
- The container element does not exist when the chart is created. Create the chart after the element is in the DOM: in React that means inside useEffect, not during render.
- Why is the chart rendering with zero height?
- The container has no height. A div with no content collapses to zero. Give it a height in CSS, or pass `chart: { height: 400 }` in the options.