Skip to content

Commit 99ae5c1

Browse files
authored
Merge pull request #123 from Makanz/feature/exponential-regression-support
Feature/exponential regression support
2 parents b123ef4 + 8c608c4 commit 99ae5c1

File tree

9 files changed

+1058
-48
lines changed

9 files changed

+1058
-48
lines changed

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# chartjs-plugin-trendline
22

3-
This plugin draws an linear trendline in your Chart.
3+
This plugin draws linear and exponential trendlines in your Chart.
44
It has been tested with Chart.js version 4.4.9.
55

66
## 📊 [View Live Examples](https://makanz.github.io/chartjs-plugin-trendline/)
@@ -35,6 +35,10 @@ ChartJS.plugins.register(chartTrendline);
3535

3636
To configure the trendline plugin you simply add a new config options to your dataset in your chart config.
3737

38+
### Linear Trendlines
39+
40+
For linear trendlines (straight lines), use the `trendlineLinear` configuration:
41+
3842
```javascript
3943
{
4044
trendlineLinear: {
@@ -51,7 +55,7 @@ To configure the trendline plugin you simply add a new config options to your da
5155
color: Color,
5256
text: string,
5357
display: boolean,
54-
displayValue: boolean,
58+
displayValue: boolean, // shows slope value
5559
offset: number,
5660
percentage: boolean,
5761
font: {
@@ -72,12 +76,65 @@ To configure the trendline plugin you simply add a new config options to your da
7276
}
7377
```
7478

79+
### Exponential Trendlines
80+
81+
For exponential trendlines (curves of the form y = a × e^(b×x)), use the `trendlineExponential` configuration:
82+
83+
```javascript
84+
{
85+
trendlineExponential: {
86+
colorMin: Color,
87+
colorMax: Color,
88+
lineStyle: string, // "dotted" | "solid" | "dashed" | "dashdot"
89+
width: number,
90+
xAxisKey: string, // optional
91+
yAxisKey: string, // optional
92+
projection: boolean, // optional
93+
trendoffset: number, // optional, if > 0 skips first n elements, if < 0 uses last n elements
94+
// optional
95+
label: {
96+
color: Color,
97+
text: string,
98+
display: boolean,
99+
displayValue: boolean, // shows exponential parameters (a, b)
100+
offset: number,
101+
font: {
102+
family: string,
103+
size: number,
104+
}
105+
},
106+
// optional
107+
legend: {
108+
text: string,
109+
strokeStyle: Color,
110+
fillStyle: Color,
111+
lineCap: string,
112+
lineDash: number[],
113+
lineWidth: number,
114+
}
115+
}
116+
}
117+
```
118+
119+
**Note:** Exponential trendlines work best with positive y-values. The equation fitted is y = a × e^(b×x), where:
120+
- `a` is the coefficient (scaling factor)
121+
- `b` is the growth rate (positive for growth, negative for decay)
122+
123+
## Examples
124+
125+
- [Linear Trendline Example](./example/lineChart.html)
126+
- [Exponential Trendline Example](./example/exponentialChart.html)
127+
- [Bar Chart with Trendline](./example/barChart.html)
128+
- [Scatter Chart with Trendline](./example/scatterChart.html)
129+
75130
## Supported chart types
76131

77132
- bar
78133
- line
79134
- scatter
80135

136+
Both linear and exponential trendlines are supported for all chart types.
137+
81138
## Contributing
82139

83140
Pull requests and issues are always welcome.

changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Changelog 3.1.0
2+
3+
### New Features
4+
- Added exponential trendline support with `trendlineExponential` configuration
5+
- Exponential trendlines fit curves of the form y = a × e^(b×x)
6+
- All existing styling options (colors, width, lineStyle, projection, etc.) work with exponential trendlines
7+
- Added comprehensive test coverage for exponential functionality
8+
- Added exponential trendline example (exponentialChart.html)
9+
10+
### Improvements
11+
- Updated README with exponential trendline documentation
12+
- Enhanced package description to mention exponential support
13+
114
# Changelog 3.0.0
215

316
### Breaking Changes

dist/chartjs-plugin-trendline.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)