- Chart.js 教程
- Chart.js - 主頁
- Chart.js - 簡介
- Chart.js - 安裝
- Chart.js - 語法
- Chart.js - 基礎
- Chart.js - 顏色
- Chart.js - 選項
- Chart.js - 互動
- Chart.js - 圖例
- Chart.js - 標題
- Chart.js - 動畫
- Chart.js - 工具提示
- Chart.js - 折線圖
- Chart.js - 柱狀圖
- Chart.js - 雷達圖
- Chart.js - 甜甜圈圖
- Chart.js - 餅圖
- Chart.js - 極區圖
- Chart.js - 氣泡圖
- Chart.js - 散點圖
- Chart.js - 混合圖表
- Chart.js - 笛卡爾座標系
- Chart.js - 分類軸
- Chart.js - 徑向軸
- Chart.js 有用的資源
- Chart.js - 快速指南
- Chart.js - 有用的資源
- Chart.js - 討論
Chart.js - 混合圖表
Chart.js 還為我們提供了建立由兩個或不同圖表型別組合而成的圖表的功能。此類圖表被稱為混合圖表。chart.js 混合圖表的常見示例之一是包含折線資料集的條形圖。
語法
在混合圖表建立語法如下 −
type: 'scatter',
datasets: [
{ type: 'scatter', data: value, },
{ type: 'bar', data: value, },
]
示例
我們舉一個例子,透過它我們將建立一個混合圖 −
<!DOCTYPE>
<html>
<head>
<meta charset- "UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>chart.js</title>
</head>
<body>
<canvas id="chartId" aria-label="chart" height="300" width="580"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.1.1/chart.min.js"></script>
<script>
var chrt = document.getElementById("chartId").getContext("2d");
var chartId = new Chart(chrt, {
type: 'scatter',
data: {
labels: ["HTML", "CSS", "JAVASCRIPT", "CHART.JS", "JQUERY", "BOOTSTRP"],
datasets: [{
type: 'scatter',
label: "online tutorial subjects",
data: [
{x:10, y:14},
{x:25, y:35},
{x:21, y:20},
{x:35, y:28},
{x:15, y:10},
{x:19, y:30}
],
backgroundColor: ['yellow', 'aqua', 'pink', 'lightgreen', 'gold', 'lightblue'],
borderColor: ['black'],
radius: 8,
},
{
type: 'polarArea',
label: "online tutorial exam",
data: [20, 40, 30, 35, 30, 20],
backgroundColor: ['navy', 'aqua', 'pink', 'lightgreen', 'lightblue', 'gold'],
borderColor: ['black'],
borderWidth: 2,
pointRadius: 5,
}
],
},
options: {
responsive: false,
scales: {
y: {
beginAtZero: true
}
}
},
});
</script>
</body>
</html>
輸出
廣告