importKatuChartsfrom'katucharts.js';import'katucharts.js/bio';// modules register their chart types on importKatuCharts.setTheme('dark');KatuCharts.setOptions({colors:KatuCharts.getPalette('sunset')});constchart=KatuCharts.chart('container',{series:[{type:'volcano',data:[/* … */]}]});
实例——数据和布局
方法
签名 → 返回值
描述
addSeries
addSeries(options, redraw=true) → BaseSeries
追加一条series;redraw=false可批量操作。
get
get(id) → BaseSeries | Axis | undefined
通过id查找series或轴。
update
update(options, redraw=true) → void
合并部分选项(title、axes、series…)。
addAxis
addAxis(options, isX=false, redraw=true) → Axis
在运行时添加轴。
redraw
redraw() → void
立即应用待决的更改。
animatedRedraw
animatedRedraw(duration=500) → void
使用过渡重绘。
reflow
reflow() → void
根据当前容器尺寸重新计算布局。
setSize
setSize(width, height) → void
设置像素尺寸并重绘。
setTitle
setTitle(titleOptions?, subtitleOptions?) → void
更新标题/副标题;null移除。
实例——导出、数据和UI
方法
签名 → 返回值
描述
getSVG
getSVG() → string
独立SVG标记。
getCSV
getCSV() → string
CSV格式的数据。
getTable
getTable() → string
HTML <table> 字符串格式的数据。
getDataRows
getDataRows() → array[][]
二维数组;首行是标头。
exportChart
exportChart({ type, filename, width, scale })
下载PNG/JPEG/SVG/PDF。
showLoading
showLoading(text='Loading...') → void
显示加载覆盖层。
hideLoading
hideLoading() → void
隐藏加载覆盖层。
getSeriesInstances
getSeriesInstances() → BaseSeries[]
所有series实例。
getXAxes / getYAxes
→ Axis[]
X / Y轴实例(多轴返回多个)。
destroy
destroy() → void
从DOM移除并解绑监听器——在移除容器前调用。
chart.showLoading('Fetching data…');fetch('/api/data').then(r=>r.json()).then(data=>{chart.addSeries({data});chart.hideLoading();});chart.exportChart({type:'image/svg+xml',filename:'report',width:1200});// on teardownchart.destroy();