Skip to content

Commit

Permalink
Customize chart
Browse files Browse the repository at this point in the history
  • Loading branch information
kucingbasah737 committed Nov 27, 2023
1 parent 06dae37 commit 5f39dcd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 104 deletions.
53 changes: 1 addition & 52 deletions views/my-links.html.njk
Original file line number Diff line number Diff line change
Expand Up @@ -57,57 +57,6 @@
Create a new link
</a>

<canvas class="my-4 w-100" id="hitsPerDayChart" width="900" height="150"></canvas>

{% endblock %}

{% block bodyEnd %}

<script src="https://cdn.jsdelivr.net/npm/chart.js@4.3.2/dist/chart.umd.js" integrity="sha384-eI7PSr3L1XLISH8JdDII5YN/njoSsxfbrkCTnJrzXt+ENP5MOVBxD+l6sEG4zoLp" crossorigin="anonymous"></script>
<script>
/* globals Chart:false */
(() => {
'use strict'
// Graphs
const ctx = document.getElementById('hitsPerDayChart')
// eslint-disable-next-line no-unused-vars
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [
{% for item in hitsPerDay %}
'{{ item.date | simpleDate }}',
{% endfor %}
],
datasets: [{
data: [
{% for item in hitsPerDay %}
{{ item.hitCount }},
{% endfor %}
],
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#007bff',
borderWidth: 4,
pointBackgroundColor: '#007bff'
}]
},
options: {
plugins: {
legend: {
display: false
},
tooltip: {
boxPadding: 3
}
}
}
})
})();
</script>
{% include "my-links.line-chart-visits.html.njk" %}

{% endblock %}
54 changes: 54 additions & 0 deletions views/my-links.line-chart-visits.html.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

<canvas class="my-4 w-100" id="hitsPerDayChart" width="900" height="100"></canvas>

<script src="https://cdn.jsdelivr.net/npm/chart.js@4.3.2/dist/chart.umd.js" integrity="sha384-eI7PSr3L1XLISH8JdDII5YN/njoSsxfbrkCTnJrzXt+ENP5MOVBxD+l6sEG4zoLp" crossorigin="anonymous"></script>

<script>
/* globals Chart:false */
(() => {
'use strict'
// Graphs
const ctx = document.getElementById('hitsPerDayChart')
// eslint-disable-next-line no-unused-vars
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [
{% for item in hitsPerDay %}
'{{ item.date | simpleDate }}',
{% endfor %}
],
datasets: [{
data: [
{% for item in hitsPerDay %}
{{ item.hitCount }},
{% endfor %}
],
lineTension: 0,
{# backgroundColor: 'transparent', #}
borderColor: '#007bff',
borderWidth: 2,
pointBackgroundColor: '#007bff',
fill: true,
}]
},
options: {
plugins: {
legend: {
display: false
},
tooltip: {
boxPadding: 3
}
},
scales: {
y: {
min: 0
},
},
}
})
})();
</script>
53 changes: 1 addition & 52 deletions views/my-links.view.html.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,6 @@
<a href="{{ basePath }}">Back to link list</a>
</p>

<canvas class="my-4 w-100" id="hitsPerDayChart" width="900" height="150"></canvas>

{% endblock %}

{% block bodyEnd %}

<script src="https://cdn.jsdelivr.net/npm/chart.js@4.3.2/dist/chart.umd.js" integrity="sha384-eI7PSr3L1XLISH8JdDII5YN/njoSsxfbrkCTnJrzXt+ENP5MOVBxD+l6sEG4zoLp" crossorigin="anonymous"></script>
<script>
/* globals Chart:false */
(() => {
'use strict'
// Graphs
const ctx = document.getElementById('hitsPerDayChart')
// eslint-disable-next-line no-unused-vars
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [
{% for item in hitsPerDay %}
'{{ item.date | simpleDate }}',
{% endfor %}
],
datasets: [{
data: [
{% for item in hitsPerDay %}
{{ item.hitCount }},
{% endfor %}
],
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#007bff',
borderWidth: 4,
pointBackgroundColor: '#007bff'
}]
},
options: {
plugins: {
legend: {
display: false
},
tooltip: {
boxPadding: 3
}
}
}
})
})();
</script>
{% include "my-links.line-chart-visits.html.njk" %}

{% endblock %}

0 comments on commit 5f39dcd

Please sign in to comment.