如何解决在图表中添加线性回归/趋势线/预测?
我有这个工作代码,它向我展示了一个散点图。现在我有两个问题。
不幸的是 chartist 似乎没有提供这样的组件,但我需要坚持代码。我有由 PHP 生成的对象/坐标数组。所以我可以使用 PHP 来使用某种线性回归代码。
这是我的代码:
var data = {
series: [{
name: 'series-1',data: [
{x:1613488823,y:124.6521},{x:1613650992,y:80.0000},{x:1613653572,y:134.4538},{x:1613677855,y:70.0000},{x:1613686204,{x:1613738264,{x:1613746985,y:79.0000},{x:1613769380,y:144.6281},{x:1613812527,y:69.0000},{x:1613903057,y:165.2810},{x:1613942647,y:75.0000},{x:1614106192,y:89.9900},{x:1614148626,y:126.9675},{x:1614297999,y:61.1670},{x:1614430915,y:149.0851},{x:1614699637,y:145.1738},{x:1614718943,y:125.0308},{x:1614795323,y:150.0000},{x:1614904587,y:117.6946},{x:1614965024,{x:1615107238,y:139.9500},{x:1615228667,y:116.6440},{x:1615306027,y:200.0000},{x:1616081480,y:109.2017},{x:1616834020,y:108.8657},{x:1617022112,y:113.4454},{x:1617027613,y:149.9500},{x:1617196815,y:179.0000},{x:1617376700,y:119.0000},{x:1617538471,{x:1617704943,{x:1617731392,y:116.0000},{x:1617748816,y:126.8908},]
},{
name: 'series-2',data: [{x:1613288823,y:90},{x:1617948816,y:150}]
}
]
}
var style = {
series: {
'series-1': {
showLine: false
},'series-2': {
showPoint: false,showLine: true
}
},chartPadding: {
top: 40,right: 0,bottom: 30,left: 0
},axisX: {
type: Chartist.AutoScaleAxis,low: 1612279223,high: 1618958416,showLabel: false,showGrid: false,},axisY: {
scaleMinSpace: 40,onlyInteger: true,high: 240,low: 0
}
}
var chart = new Chartist.Line('.ct-chart',data,style);
<script src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
<link href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css" rel="stylesheet"/>
<div class="sale-chart" style="width:500px;height:300px;">
<div class="ct-chart ct-perfect-fourth" style="width:100%;height:100%;"></div>
</div>
如您所见,我已经设法添加了具有静态值(红线)的第二层。但是如何通过数据对象给出的代码逻辑获得两个值(y:90 和 y:150)?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。