diff --git a/README.md b/README.md index 3f601bb..080c524 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # chartjs-plugin-trendline -This plugin draws an linear trendline in your Chart. Made for Chart.js > 2.0 +This plugin draws an linear trendline in your Chart. Made for Chart.js 3.X ## Installation @@ -9,7 +9,7 @@ This plugin draws an linear trendline in your Chart. Made for Chart.js > 2.0 Load ChartJS first, then the plugin which will automatically register itself with ChartJS ```html - + ``` diff --git a/dist/chartjs-plugin-trendline.min.js b/dist/chartjs-plugin-trendline.min.js index d3ed496..bd7dcc4 100644 --- a/dist/chartjs-plugin-trendline.min.js +++ b/dist/chartjs-plugin-trendline.min.js @@ -1 +1 @@ -var pluginTrendlineLinear={id:"trendlineLinear",afterDraw:function(a){var t,s;for(var e in a.scales)if("x"==e[0]?s=a.scales[e]:t=a.scales[e],s&&t)break;var n=a.chart.ctx;a.data.datasets.forEach(function(t,e){if(t.trendlineLinear&&a.isDatasetVisible(e)&&0!=t.data.length){var i=a.getDatasetMeta(e);addFitter(i,n,t,s,a.scales[i.yAxisID])}}),n.setLineDash([])}};function addFitter(t,e,i,a,s){var n=i.trendlineLinear.style||i.borderColor,r=i.trendlineLinear.width||i.borderWidth,o=i.trendlineLinear.lineStyle||"solid";n=void 0!==n?n:"rgba(169,169,169, .6)",r=void 0!==r?r:3;var l=new LineFitter,d=i.data.length-1,h=t.data[0]._model.x,u=t.data[d]._model.x,m=!1;i.data&&"object"==typeof i.data[0]&&(m=!0),i.data.forEach(function(t,e){if(null!=t)if("time"===a.options.type){var i=null!=t.x?t.x:t.t;l.add(new Date(i).getTime(),t.y)}else m?l.add(t.x,t.y):l.add(e,t)});var x=a.getPixelForValue(l.minx),c=a.getPixelForValue(l.maxx),f=s.getPixelForValue(l.f(l.minx)),g=s.getPixelForValue(l.f(l.maxx));m||(x=h,c=u);var p=t.controller.chart.chartArea.bottom,v=t.controller.chart.width;if(pthis.maxx&&(this.maxx=t)},f:function(t){t=parseFloat(t);var e=this.count*this.sumX2-this.sumX*this.sumX;return(this.sumX2*this.sumY-this.sumX*this.sumXY)/e+t*((this.count*this.sumXY-this.sumX*this.sumY)/e)}},"undefined"!=typeof window&&window.Chart&&window.Chart.plugins.register(pluginTrendlineLinear);try{module.exports=exports=pluginTrendlineLinear}catch(t){} \ No newline at end of file +var pluginTrendlineLinear={id:"chartjs-plugin-trendline",afterDraw:function(a){var t,s;for(var i in a.scales)if("x"==i[0]?s=a.scales[i]:t=a.scales[i],s&&t)break;var r=a.ctx;a.data.datasets.forEach(function(t,i){if(t.trendlineLinear&&a.isDatasetVisible(i)&&0!=t.data.length){var e=a.getDatasetMeta(i);addFitter(e,r,t,s,a.scales[e.yAxisID])}}),r.setLineDash([])}};function addFitter(t,i,e,a,s){var r=e.trendlineLinear.style||e.borderColor,n=e.trendlineLinear.width||e.borderWidth,o=e.trendlineLinear.lineStyle||"solid";r=void 0!==r?r:"rgba(169,169,169, .6)",n=void 0!==n?n:3;var l=new LineFitter,d=e.data.length-1,h=t.data[0].x,u=t.data[d].x,m=!1;e.data&&"object"==typeof e.data[0]&&(m=!0),e.data.forEach(function(t,i){if(null!=t)if("time"===a.options.type){var e=null!=t.x?t.x:t.t;l.add(new Date(e).getTime(),t.y)}else m?l.add(t.x,t.y):l.add(i,t)});var x=a.getPixelForValue(l.minx),c=a.getPixelForValue(l.maxx),f=s.getPixelForValue(l.f(l.minx)),g=s.getPixelForValue(l.f(l.maxx));m||(x=h,c=u);var p=t.controller.chart.chartArea.bottom,v=t.controller.chart.width;if(pthis.maxx&&(this.maxx=t)},f:function(t){t=parseFloat(t);var i=this.count*this.sumX2-this.sumX*this.sumX;return(this.sumX2*this.sumY-this.sumX*this.sumXY)/i+t*((this.count*this.sumXY-this.sumX*this.sumY)/i)}},void 0!==typeof window&&window.Chart&&(window.Chart.hasOwnProperty("register")?window.Chart.register(pluginTrendlineLinear):window.Chart.plugins.register(pluginTrendlineLinear));try{module.exports=exports=pluginTrendlineLinear}catch(t){} \ No newline at end of file diff --git a/example/ScatterChart.html b/example/ScatterChart.html deleted file mode 100644 index cadd626..0000000 --- a/example/ScatterChart.html +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - ScatterChart Example - - - - - -

Line Chart

- - -

Using example code from tobiasahlin.com.

- - \ No newline at end of file diff --git a/example/XYlineChart.html b/example/XYlineChart.html deleted file mode 100644 index 224b5a0..0000000 --- a/example/XYlineChart.html +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - XYlineChart Example - - - - - -

Scatter Chart

- - -

Using example code from tobiasahlin.com.

- - \ No newline at end of file diff --git a/example/barChart.html b/example/barChart.html index 44968a1..e95ed54 100644 --- a/example/barChart.html +++ b/example/barChart.html @@ -5,7 +5,7 @@ BarChart Example - + +