【发布时间】:2015-11-05 21:36:21
【问题描述】:
我正在尝试根据 mx+b(斜率 + y 截距)公式在 Highcharts 中绘制线性回归线,并使用 regression-js 生成回归公式。
我遇到的问题是,Highcharts 似乎想要[[x1, y1], [x2, y2]] 格式的回归线,但我不一定能从斜率和 y 截距中得到起点和终点。
所以:
是否可以根据斜率在 Highcharts 中画一条线?或者是否有一个 JS 回归库可以根据我下面的数据数组输出 [[x1, y1], [x2, y2]] 格式的行?
我现在的工作:
data = [[11.6,14.7],[12.2,15.9],[10.7,14.8],[14,11.7],[12.5,13.2],[10,11.3],[10.1,11],[13.5,19.1]];
slope = regression('linear', data); // result: slope.equation = [slope, y-intercept]
$('#scatter').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy'
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x} cm, {point.y} kg'
}
}
},
series: [
{
type: 'line',
name: 'Regression Line',
data: [[0, 0], [5, 4.51]], // You see the problem here: I've got mx + b and this wants x1 y1 x2 y2
marker: {
enabled: false
},
states: {
hover: {
lineWidth: 0
}
},
enableMouseTracking: false
},
{
name: 'Water Temperature vs. Air Temperature',
color: 'rgba(119, 152, 191, .5)',
data: data
}]
});
【问题讨论】:
标签: javascript highcharts statistics linear-regression