hugo-chartHugo 站點(diǎn) Chart 圖表組件
這是一個(gè)為 Hugo 而寫(xiě)的 Chart.js 圖表組件,用 chart 短代碼就可以方便的把優(yōu)雅的動(dòng)態(tài)圖表插入到你的 Hugo 站點(diǎn)中。
用法
-
用
git submodule add https://github.com/Shen-Yu/hugo-chart.git themes/hugo-chart命令把 hugo-chart 添加為項(xiàng)目的子模塊。 -
找到 Hugo 站點(diǎn)根目錄下的配置文件(
config.yaml或config.toml),把hugo-chart添加到theme選項(xiàng)的最左側(cè),以下是config.yamltheme: ["hugo-chart", "my-theme"]
以下是
config.tomltheme = ["hugo-chart", "my-theme"]
-
在你的站點(diǎn)文章或頁(yè)面中,插入以下格式的短代碼
{{< chart [寬度] [高度] >}} // 這里是 Chartjs 的配置 {{< /chart >}}名稱 類型 默認(rèn) 描述 width decimal 100% 圖表寬度,默認(rèn)是響應(yīng)式的 height number 300 圖表高度(px) -
注意 Chartjs 默認(rèn)是響應(yīng)式的, 為了使自定義寬高生效, 你需要先把
maintainAspectRatio選項(xiàng)設(shè)置成false。
例子
{{< chart 100 300 >}}
{
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: 'Bar Chart',
data: [12, 19, 18, 16, 13, 14],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
maintainAspectRatio: false,
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
}
{{< /chart >}}
評(píng)論
圖片
表情
