笛卡尔坐标

折线图

type: 'line'

标准折线图,用直线段连接数据点。支持标记、数据标签、区域、负值颜色、阶跃插值和虚线样式。

编辑右侧的JSON并按Run(或⌘/Ctrl + Enter)——数据、标题、类别和颜色全部实时更新。

实时
折线图
编辑 · JSON

数据格式

[10, 20, 30] · [[0,10],[1,20]] · [{ x: 0, y: 10 }]

数据结构

传入图表的 JSON——可直接放进你的 series。

series: [
  { name: '线上', data: [42, 48, 55, 51, 63, 71] },
  { name: '门店', data: [31, 34, 30, 37, 39, 44] }
]

示例

import KatuCharts from 'katucharts.js';

KatuCharts.chart('container', {
  chart: { type: 'line' },
  xAxis: { categories: ['1月', '2月', '3月', '4月', '5月', '6月'] },
  series: [
    { name: '线上', data: [42, 48, 55, 51, 63, 71] },
    { name: '门店', data: [31, 34, 30, 37, 39, 44], dashStyle: 'Dash' }
  ]
});

类型特定选项

选项描述
lineWidth线条宽度(默认2)。
dashStyle'Solid'、'Dash'、'Dot'、'DashDot'等。
marker点标记——{ symbol、radius、enabled }。
connectNulls从空值桥接间隙。
negativeColor低于阈值的值的颜色。
zones按值的范围着色。
step'left' | 'center' | 'right'阶跃插值。

变体

标记与虚线样式

为每个系列启用数据点标记,并用 dashStyle 区分线条。

KatuCharts.chart('container', {
  chart: { type: 'line' },
  series: [
    { name: '线上', data: [42, 48, 55, 51, 63, 71], marker: { enabled: true } },
    { name: '门店', data: [31, 34, 30, 37, 39, 44], dashStyle: 'Dash' }
  ]
});

阶梯线与分区

阶梯插值配合按值分区,在阈值处为线条重新着色。

KatuCharts.chart('container', {
  chart: { type: 'line' },
  series: [{
    data: [-6, -2, 4, 9, 16, 22], step: 'center',
    dataLabels: { enabled: true, format: '{point.y}°' },
    zones: [{ value: 0, color: '#2F6B5E' }, { color: '#B43417' }]
  }]
});

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: 'line' }, 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.
通用选项(color、visible、marker、dataLabels、animation、events、zones…)适用于每个类型——请参阅配置→series。在图库中查看其渲染。