新手上路,操作不咋地大佬可以指點指點
第一步當然去highchart官網下載所需的JS附上我所用的
第二步個人建議可以去copy別人的模板附上一個我自己用的地址
模板網址
第三步就是把從自己數據庫裏面查出來的值附上去不多說上代碼
<script>
var chat=Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: '2019年數據庫使用份額'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: []
}]
});
$(function () {
$.get(
"/getfind"
,function (data) {
var RstData=[];
for(var i=0;i<data.length;i++){
RstData.push([data[i].shujuku,data[i].bili]);
}
chat.series[0].update({
data:RstData
});
}
)
})
</script>
還有個HTML的標籤
<div id="container" style="min-width:400px;height:400px"></div>
就這樣一個餅狀圖就弄好了最後附上一張完成圖
至於柱狀圖其實大概和餅狀圖差不多隻是模板不一樣而已或者樣式不一樣同理柱狀圖把餅狀圖代碼copy過去就差不多了附上完成圖一張
哈哈我選的這個模板是3D的感覺視覺效果好看點,個人感覺做這個不是很難就是耐心要好。好了餅狀圖和柱狀圖都做完了。