Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slope percentage #98

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# chartjs-plugin-trendline

This plugin draws an linear trendline in your Chart.
It has been tested with Chart.js version 4.4.3.
It has been tested with Chart.js version 4.4.4.

## Installation

Expand All @@ -10,7 +10,7 @@ It has been tested with Chart.js version 4.4.3.
Load Chart.js first, then the plugin which will automatically register itself with Chart.js

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].3/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
```

Expand Down Expand Up @@ -48,6 +48,7 @@ To configure the trendline plugin you simply add a new config options to your da
display: boolean,
displayValue: boolean,
offset: number,
percentage: boolean,
font: {
family: string,
size: number,
Expand Down
2 changes: 1 addition & 1 deletion dist/chartjs-plugin-trendline.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/chartjs-plugin-trendline.min.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* chartjs-plugin-trendline.js
* Version: 2.1.5
* Version: 2.1.6
*
* Copyright 2024 Marcus Alsterfjord
* Released under the MIT license
Expand Down
64 changes: 34 additions & 30 deletions example/barChart.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>BarChart Example</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected].3/dist/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/chart.umd.js"></script>
<script src="./../src/chartjs-plugin-trendline.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
// Bar chart
new Chart(document.getElementById("bar-chart"), {
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433],
trendlineLinear: {
colorMin: "rgba(255,105,180, .8)",
lineStyle: "dotted",
width: 2
}
},
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
document.addEventListener("DOMContentLoaded", function (event) {
// Bar chart
new Chart(document.getElementById("bar-chart"), {
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2", "#3cba9f", "#e8c3b9", "#c45850"],
data: [2478, 5267, 734, 784, 433],
trendlineLinear: {
colorMin: "rgba(255,105,180, .8)",
lineStyle: "dotted",
width: 2
}
});
});
</script>
},
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
}
});
});
</script>
</head>

<body>
<h1>Bar Chart</h1>

<div style="width: 800px;">
<canvas id="bar-chart"></canvas>
</div>

<p>Using example code from <a href="http://tobiasahlin.com/blog/chartjs-charts-to-get-you-started/" target="_blank">tobiasahlin.com.</a></p>
<p>Using example code from <a href="http://tobiasahlin.com/blog/chartjs-charts-to-get-you-started/"
target="_blank">tobiasahlin.com.</a></p>
</body>

</html>
64 changes: 34 additions & 30 deletions example/barChartWithNullValues.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>BarChart Example</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected].3/dist/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].4/dist/chart.umd.js"></script>
<script src="./../src/chartjs-plugin-trendline.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
// Bar chart
new Chart(document.getElementById("bar-chart"), {
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "Undefined", "null", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,undefined, null,433],
trendlineLinear: {
colorMin: "rgba(255,105,180, .8)",
lineStyle: "dotted",
width: 2
}
},
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
document.addEventListener("DOMContentLoaded", function (event) {
// Bar chart
new Chart(document.getElementById("bar-chart"), {
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "Undefined", "null", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2", "#3cba9f", "#e8c3b9", "#c45850"],
data: [2478, 5267, 734, 784, undefined, null, 433],
trendlineLinear: {
colorMin: "rgba(255,105,180, .8)",
lineStyle: "dotted",
width: 2
}
});
});
</script>
},
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
}
});
});
</script>
</head>

<body>
<h1>Bar Chart</h1>

<div style="width: 800px;">
<canvas id="bar-chart"></canvas>
</div>

<p>Using example code from <a href="http://tobiasahlin.com/blog/chartjs-charts-to-get-you-started/" target="_blank">tobiasahlin.com.</a></p>
<p>Using example code from <a href="http://tobiasahlin.com/blog/chartjs-charts-to-get-you-started/"
target="_blank">tobiasahlin.com.</a></p>
</body>

</html>
61 changes: 61 additions & 0 deletions example/barChart_label.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>BarChart Example</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.js"></script>
<script src="./../src/chartjs-plugin-trendline.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function (event) {
// Bar chart
new Chart(document.getElementById("bar-chart"), {
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2", "#3cba9f", "#e8c3b9", "#c45850"],
data: [500, 1555, 650, 1555, 2505],
trendlineLinear: {
label: {
color: "#000",
text: "Trendline label",
display: true,
percentage: true,
offset: 10
},
colorMin: "rgba(255,105,180, .8)",
lineStyle: "dotted",
width: 2
}
},
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
}
});
});
</script>
</head>

<body>
<h1>Bar Chart</h1>

<div style="width: 800px;">
<canvas id="bar-chart"></canvas>
</div>

<p>Using example code from <a href="http://tobiasahlin.com/blog/chartjs-charts-to-get-you-started/"
target="_blank">tobiasahlin.com.</a></p>
</body>

</html>
Loading