forked from alshedivat/al-folio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Chart.js (alshedivat#2126)
Solved alshedivat#460. ![image](https://github.com/alshedivat/al-folio/assets/31376482/ce65dbe2-031e-4208-b374-08ec89beaaca) --------- Signed-off-by: George Araújo <[email protected]>
- Loading branch information
1 parent
1d84621
commit a7d6b37
Showing
5 changed files
with
213 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% if page.chart %} | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script> | ||
<script> | ||
$(document).ready(function () { | ||
var $canvas = null, | ||
$this = null, | ||
_ctx = null, | ||
_text = ''; | ||
$('.language-chart').each(function () { | ||
$this = $(this); | ||
$canvas = $('<canvas></canvas>'); | ||
_text = $this.text(); | ||
$this.text('').append($canvas); | ||
_ctx = $canvas.get(0).getContext('2d'); | ||
_ctx && _text && new Chart(_ctx, JSON.parse(_text)) && $this.attr('data-processed', true); | ||
}); | ||
}); | ||
</script> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
--- | ||
layout: post | ||
title: a post with chart.js | ||
date: 2024-01-26 01:04:00 | ||
description: this is what included chart.js code could look like | ||
tags: formatting charts | ||
categories: sample-posts | ||
chart: true | ||
--- | ||
|
||
This is an example post with some chart.js code. | ||
|
||
````markdown | ||
```chart | ||
{ | ||
"type": "line", | ||
"data": { | ||
"labels": [ | ||
"January", | ||
"February", | ||
"March", | ||
"April", | ||
"May", | ||
"June", | ||
"July" | ||
], | ||
"datasets": [ | ||
{ | ||
"label": "# of bugs", | ||
"fill": false, | ||
"lineTension": 0.1, | ||
"backgroundColor": "rgba(75,192,192,0.4)", | ||
"borderColor": "rgba(75,192,192,1)", | ||
"borderCapStyle": "butt", | ||
"borderDash": [], | ||
"borderDashOffset": 0, | ||
"borderJoinStyle": "miter", | ||
"pointBorderColor": "rgba(75,192,192,1)", | ||
"pointBackgroundColor": "#fff", | ||
"pointBorderWidth": 1, | ||
"pointHoverRadius": 5, | ||
"pointHoverBackgroundColor": "rgba(75,192,192,1)", | ||
"pointHoverBorderColor": "rgba(220,220,220,1)", | ||
"pointHoverBorderWidth": 2, | ||
"pointRadius": 1, | ||
"pointHitRadius": 10, | ||
"data": [ | ||
65, | ||
59, | ||
80, | ||
81, | ||
56, | ||
55, | ||
40 | ||
], | ||
"spanGaps": false | ||
} | ||
] | ||
}, | ||
"options": {} | ||
} | ||
``` | ||
```` | ||
|
||
This is how it looks like: | ||
|
||
```chart | ||
{ | ||
"type": "line", | ||
"data": { | ||
"labels": [ | ||
"January", | ||
"February", | ||
"March", | ||
"April", | ||
"May", | ||
"June", | ||
"July" | ||
], | ||
"datasets": [ | ||
{ | ||
"label": "# of bugs", | ||
"fill": false, | ||
"lineTension": 0.1, | ||
"backgroundColor": "rgba(75,192,192,0.4)", | ||
"borderColor": "rgba(75,192,192,1)", | ||
"borderCapStyle": "butt", | ||
"borderDash": [], | ||
"borderDashOffset": 0, | ||
"borderJoinStyle": "miter", | ||
"pointBorderColor": "rgba(75,192,192,1)", | ||
"pointBackgroundColor": "#fff", | ||
"pointBorderWidth": 1, | ||
"pointHoverRadius": 5, | ||
"pointHoverBackgroundColor": "rgba(75,192,192,1)", | ||
"pointHoverBorderColor": "rgba(220,220,220,1)", | ||
"pointHoverBorderWidth": 2, | ||
"pointRadius": 1, | ||
"pointHitRadius": 10, | ||
"data": [ | ||
65, | ||
59, | ||
80, | ||
81, | ||
56, | ||
55, | ||
40 | ||
], | ||
"spanGaps": false | ||
} | ||
] | ||
}, | ||
"options": {} | ||
} | ||
``` | ||
|
||
Also another example chart. | ||
|
||
````markdown | ||
```chart | ||
{ | ||
"type": "doughnut", | ||
"data": { | ||
"labels": [ | ||
"Red", | ||
"Blue", | ||
"Yellow" | ||
], | ||
"datasets": [ | ||
{ | ||
"data": [ | ||
300, | ||
50, | ||
100 | ||
], | ||
"backgroundColor": [ | ||
"#FF6384", | ||
"#36A2EB", | ||
"#FFCE56" | ||
], | ||
"hoverBackgroundColor": [ | ||
"#FF6384", | ||
"#36A2EB", | ||
"#FFCE56" | ||
] | ||
} | ||
] | ||
}, | ||
"options": {} | ||
} | ||
``` | ||
```` | ||
|
||
Which generates: | ||
|
||
```chart | ||
{ | ||
"type": "doughnut", | ||
"data": { | ||
"labels": [ | ||
"Red", | ||
"Blue", | ||
"Yellow" | ||
], | ||
"datasets": [ | ||
{ | ||
"data": [ | ||
300, | ||
50, | ||
100 | ||
], | ||
"backgroundColor": [ | ||
"#FF6384", | ||
"#36A2EB", | ||
"#FFCE56" | ||
], | ||
"hoverBackgroundColor": [ | ||
"#FF6384", | ||
"#36A2EB", | ||
"#FFCE56" | ||
] | ||
} | ||
] | ||
}, | ||
"options": {} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters