其他
时间线
type: 'timeline'沿一条线排列的顺序事件标记;每个点都是一个里程碑,包含名称、简短标签和可选的描述(显示在提示框中)。默认水平,设置 chart.inverted 时为垂直。
编辑右侧的JSON并按Run(或⌘/Ctrl + Enter)——数据、标题、类别和颜色全部实时更新。
实时
时间线
编辑 · JSON
数据格式
{ name: string, label?, description?, color? }
数据结构
传入图表的 JSON——可直接放进你的 series。
data: [
{ name: 'Founded', label: '2019', description: 'First prototype shipped.' },
{ name: 'Series A', label: '2022', description: '$15M raised; team of 40.' },
{ name: 'v1.0', label: '2024', description: 'General availability launch.' }
]示例
import KatuCharts from 'katucharts.js';
KatuCharts.chart('container', {
chart: { type: 'timeline' },
series: [{
data: [
{ name: 'Founded', label: '2019', description: 'First prototype shipped.' },
{ name: 'Series A', label: '2022', description: '$15M raised; team of 40.' },
{ name: 'v1.0', label: '2024', description: 'General availability launch.' }
]
}]
});类型特定选项
| 选项 | 描述 |
|---|---|
dataLabels.format | 每个点的标签模板,例如 '<b>{point.name}</b><br>{point.label}'。 |
dataLabels.alternate | 在线条两侧交错显示标签(默认 true)。 |
dataLabels.distance | 标记与其标签之间的间距(默认 22)。 |
chart.inverted | 将时间线纵向排列而非横向。 |
marker | 每个点的标记 — { symbol, radius, lineColor, lineWidth }。 |
colorByPoint | 从调色板为每个标记着色(默认 true)。 |
变体
垂直(反转)
设置 chart.inverted 可将时间线纵向排列——非常适合窄列和学历背景展示。
KatuCharts.chart('container', {
chart: { type: 'timeline', inverted: true },
series: [{
data: [
{ name: "Bachelor's", label: '2006 – 2008', description: 'Computer Networks — FAZ, Brazil' },
{ name: "Master's", label: '2014 – 2016', description: 'Computer Science — UFPA, Brazil' },
{ name: 'Doctorate', label: '2018 – 2022', description: 'Artificial Intelligence — USP, Brazil' }
]
}]
});提示框中的描述
为每个点提供描述,悬停时会显示在提示框中,从而保持图表上的标签简短。
KatuCharts.chart('container', {
chart: { type: 'timeline' },
tooltip: { pointFormat: '{point.description}' },
series: [{
data: [
{ name: 'Founded', label: '2019', description: 'First prototype shipped.' },
{ name: 'Series A', label: '2022', description: '$15M raised; team of 40.' },
{ name: 'v1.0', label: '2024', description: 'General availability launch.' }
]
}]
});单侧标签
将 dataLabels.alternate 设为 false,让所有标签都位于线条的同一侧。
KatuCharts.chart('container', {
chart: { type: 'timeline' },
series: [{
dataLabels: { alternate: false },
data: [
{ name: 'v1.0', label: '1月' },
{ name: 'v1.5', label: '4月' },
{ name: 'v2.0', label: '8月' },
{ name: 'v2.4', label: '11月' }
]
}]
});纯文本标签(圆形标记)
将 dataLabels.borderWidth 设为 0 即可去掉方框,让更大的圆形标记承载时间线。
KatuCharts.chart('container', {
chart: { type: 'timeline' },
series: [{
marker: { radius: 9 },
dataLabels: { borderWidth: 0 },
data: [
{ name: 'Discovery', label: '一季度' },
{ name: '设计', label: '二季度' },
{ name: 'Build', label: '三季度' },
{ name: 'Launch', label: '四季度' }
]
}]
});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: 'timeline' }, 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.