Highcharts 散点图上添加回归线
下图是一个 Highcharts 散点图上添加回归线
配置
配置属性 series.type 属性为 line/scatter
var series = { type: 'scatter' };
范例
下面的代码列出了 Highcharts 散点图上添加回归线 的基本配置
<!doctype html> <meta charset="utf-8" /> <title>Highcharts 基础教程 | 简单教程(www.twle.cn)</title> <script src="https://cdn.hcharts.cn/highcharts/highcharts.js"></script> <div id="container" style="width: 500px; height: 400px; margin: 0 auto"></div> <script> var title = { text: '散点图上添加回归线' }; var xAxis = { min: -0.5, max: 5.5 }; var yAxis= { min: 0 }; var series= [{ type: 'line', name: '回归线', data: [[0, 1.11], [5, 4.51]], marker: { enabled: false }, states: { hover: { lineWidth: 0 } }, enableMouseTracking: false }, { type: 'scatter', name: '观察点', data: [1, 1.5, 2.8, 3.5, 3.9, 4.2], marker: { radius: 4 } } ]; var options = {}; options.title = title; options.xAxis = xAxis; options.yAxis = yAxis; options.series = series; Highcharts.chart('container',options); </script>
以上范例输出如下