後台傳遞 JSON 數據,前端以柱狀圖、餅圖等形式可視化,用於監控大屏/報表。
jquery.js、jquery.jqChart.min.js、jquery.jqChart.css、excanvas.js (IE8- 兼容)。
<link href="jquery.jqChart.css" rel="stylesheet">
<script src="jquery.js"></script>
<script src="excanvas.js"></script> <!-- IE8- -->
<script src="jquery.jqChart.min.js"></script>
<div id="chart" style="width:600px;height:400px;"></div>
$(function() {
// 假設後台返回:[{label:"產品A", value:120}, {label:"產品B", value:90}, ...]
$.getJSON('/api/chartData', function(data) {
$('#chart').jqChart({
title: { text: '月度銷售額' },
animation: { enabled: true },
series: [{
type: 'column',
data: data.map(d => [d.label, d.value]) // [[label, value], ...]
}],
axes: [
{ location: 'left', type: 'linear' },
{ location: 'bottom', type: 'category' }
]
});
});
});
series: [{type:'column', data:...}, {type:'column', data:...}] + stacked: true。tooltips: { stringFormat: '%.2f' }, click: function(e, data) { ... }。width:100%,窗口 resize 時 $('#chart').jqChart('update')。| 庫 | 許可證 | 特點 |
|---|---|---|
| ECharts | Apache 2.0 | 百度出品、功能最全、生態最強、中文文檔佳、推薦首選 |
| Chart.js | MIT | Canvas 繪圖、輕量、API 簡潔、移動端友好 |
| Highcharts | 商業/免費非商業 | 功能強、文檔詳、商業項目需授權 |
| AntV (G2/F2) | MIT | 螞蟻金服、語法語義化、React/Vue 組件豐富 |
jqChart 適合「jQuery 老項目快速接入」,新項目**強烈推薦 ECharts 或 AntV**,功能更豐富、社區更活躍、長期維護有保障。