使用jQuery jqPlot插件繪制柱狀圖
在一個(gè)項(xiàng)目研發(fā)過(guò)程中,需要顯示賬戶(hù)的資金情況,為了給客戶(hù)良好的體驗(yàn)我們采用了柱狀圖形展現(xiàn),繪圖的過(guò)程如果使用原生態(tài)腳本繪制這樣比較麻煩,時(shí)間也會(huì)比較長(zhǎng),所以我們選擇了jqPlot插件進(jìn)行繪制,這樣可以節(jié)省大量的時(shí)間,也能很快就能展示給用戶(hù)。
插件官方地址:http://www.jqplot.com/
具體實(shí)現(xiàn)如下:
引用JS文件:
<link href="~/Scripts/asset/jqplot/jquery.jqplot.min.css" rel="stylesheet" />
<link href="~/Scripts/asset/jqplot/syntaxhighlighter/styles/shCoreDefault.min.css" rel="stylesheet" />
<link href="~/Scripts/asset/jqplot/syntaxhighlighter/styles/shThemejqPlot.min.css" rel="stylesheet" />
<script src="~/Scripts/asset/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="~/Scripts/asset/jqplot/jquery.jqplot.min.js" class="include"></script>
<script type="text/javascript" src="~/Scripts/asset/jqplot/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="~/Scripts/asset/jqplot/syntaxhighlighter/scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="~/Scripts/asset/jqplot/syntaxhighlighter/scripts/shBrushXml.js"></script>
<script type="text/javascript" src="~/Scripts/asset/jqplot/excanvas.min.js"></script>
<script type="text/javascript" src="~/Scripts/asset/jqplot/plugins/jqplot.barRenderer.min.js"></script>
<script type="text/javascript" src="~/Scripts/asset/jqplot/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript" src="~/Scripts/asset/jqplot/plugins/jqplot.pointLabels.min.js"></script>
Html代碼
<div id="chart1" class="box"></div>
Javascript腳本:
var chartBar = function () {
var data={param1:param1,param2:param2};//傳遞參數(shù)
$("#chart1").html("");//繪圖DIV
var s1;
$.ajax({
type: "POST",
url: '../Home/AccountSum',
data: data,
datatype: "json",
async: false,
success: function (d) {
if (d.flag) {
s1 = [parseFloat(d.data.Total1), parseFloat(d.data.Total2), parseFloat(d.data.Total3), parseFloat(d.data.Total4), parseFloat(d.data.Total5), parseFloat(d.data.Total6)];
} else {
s1 = [0.00, 0.00, 0.00, 0.00, 0.00, 0.00];
}
$.jqplot.config.enablePlugins = true;
var ticks = ['充值', '提款', '應(yīng)收', '銷(xiāo)售', '退票', '驗(yàn)證'];
var plot1 = $.jqplot('chart1', [s1], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
//animate: !$.jqplot.use_excanvas,
seriesDefaults: {
pointLabels: { show: true },
shadow: false,
showMarker: true, // 是否強(qiáng)調(diào)顯示圖中的數(shù)據(jù)節(jié)點(diǎn)
renderer: $.jqplot.BarRenderer,
rendererOptions: {
barWidth: 50,
barMargin: 50
}
},
axes: {
xaxis: {
show: true, //是否自動(dòng)顯示坐標(biāo)軸
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks,
showTicks: true, // 是否顯示刻度線(xiàn)以及坐標(biāo)軸上的刻度值
showTickMarks: true, //設(shè)置是否顯示刻度
tickOptions: {
show: true,
fontSize: '14px',
fontFamily: 'tahoma,arial,"Hiragino Sans GB",宋體b8b體,sans-serif',
showLabel: true, //是否顯示刻度線(xiàn)以及坐標(biāo)軸上的刻度值
showMark: false,//設(shè)置是否顯示刻度
showGridline: false // 是否在圖表區(qū)域顯示刻度值方向的網(wǎng)格
}
},
yaxis: {
show: true,
showTicks: false, // 是否顯示刻度線(xiàn)以及坐標(biāo)軸上的刻度值
showTickMarks: false, //設(shè)置是否顯示刻度
autoscale: true,
borderWidth: 1,
tickOptions: {
show: true,
showLabel: false,
showMark: false,
showGridline: true,
formatString: '¥%.2f'
}
},
},
grid: {
drawGridLines: true,
drawBorder: false,
shadow: false,
borderColor: '#000000', // 設(shè)置圖表的(最外側(cè))邊框的顏色
borderWidth: 1 //設(shè)置圖表的(最外側(cè))邊框?qū)挾?nbsp;
},
highlighter: { show: false }
});
},
error: function () {
alert("獲取圖形統(tǒng)計(jì)數(shù)據(jù)失敗!");
}
});
};
效果圖:
今天就寫(xiě)到這里吧,初步看了一下官方上的事例,功能還是蠻強(qiáng)大的,使用也很方便、容易,根據(jù)本項(xiàng)目的需求,后續(xù)可能還會(huì)增加一些。不過(guò)在使用過(guò)程中也發(fā)現(xiàn)了一些問(wèn)題,部分實(shí)現(xiàn)不一定可以滿(mǎn)足。
- jQuery插件FusionCharts繪制2D雙折線(xiàn)圖效果示例【附demo源碼】
- jQuery插件FusionCharts繪制的2D雙面積圖效果示例【附demo源碼】
- jQuery插件FusionCharts繪制2D柱狀圖和折線(xiàn)圖的組合圖效果示例【附demo源碼】
- jQuery插件FusionCharts繪制2D環(huán)餅圖效果示例【附demo源碼】
- jQuery插件FusionCharts繪制的2D帕累托圖效果示例【附demo源碼】
- jQuery插件FusionCharts實(shí)現(xiàn)的MSBar2D圖效果示例【附demo源碼】
- jQuery插件FusionCharts繪制ScrollColumn2D圖效果示例【附demo源碼下載】
- jQuery插件FusionCharts實(shí)現(xiàn)的2D面積圖效果示例【附demo源碼下載】
- jQuery插件FusionCharts實(shí)現(xiàn)的2D柱狀圖效果示例【附demo源碼下載】
- jQuery插件FusionCharts實(shí)現(xiàn)的2D餅狀圖效果【附demo源碼下載】
- jQuery插件ImageDrawer.js實(shí)現(xiàn)動(dòng)態(tài)繪制圖片動(dòng)畫(huà)(附源碼下載)
- jQuery插件FusionCharts繪制的2D雙柱狀圖效果示例【附demo源碼】
相關(guān)文章
使用jquery提交form表單并自定義action的實(shí)現(xiàn)代碼
下面小編就為大家?guī)?lái)一篇使用jquery提交form表單并自定義action的實(shí)現(xiàn)代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05jQuery實(shí)現(xiàn)動(dòng)態(tài)添加節(jié)點(diǎn)與遍歷節(jié)點(diǎn)功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)動(dòng)態(tài)添加節(jié)點(diǎn)與遍歷節(jié)點(diǎn)功能,結(jié)合實(shí)例形式分析了jQuery針對(duì)頁(yè)面元素節(jié)點(diǎn)元素的動(dòng)態(tài)添加與遍歷相關(guān)操作技巧,需要的朋友可以參考下2017-11-11JQuery驗(yàn)證jsp頁(yè)面屬性是否為空(實(shí)例代碼)
JQuery驗(yàn)證jsp頁(yè)面屬性是否為空的實(shí)例代碼。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-11-11解析jQuery與其它js(Prototype)庫(kù)兼容共存
解決jQuery與其它js(Prototype)庫(kù)沖突的方法很簡(jiǎn)單,就是使用jQuery的jQuery.noConflict()函數(shù),以下小編就為大家介紹,需要的朋友可以參考下2013-07-07詳解Jquery 遍歷數(shù)組之$().each方法與$.each()方法介紹
這篇文章主要介紹了詳解Jquery 遍歷數(shù)組之$().each方法與$.each()方法介紹 ,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01用jQuery的AJax實(shí)現(xiàn)異步訪(fǎng)問(wèn)、異步加載
這篇文章主要介紹了用jQuery的AJax實(shí)現(xiàn)異步訪(fǎng)問(wèn)、異步加載,jQuery的ajax異步實(shí)現(xiàn)數(shù)據(jù)交互的相關(guān)技巧,并提供了完整示例demo供讀者參考,需要的朋友可以參考下2016-11-11jquery實(shí)現(xiàn)鼠標(biāo)拖拽滑動(dòng)效果來(lái)選擇數(shù)字的方法
這篇文章主要介紹了jquery實(shí)現(xiàn)鼠標(biāo)拖拽滑動(dòng)效果來(lái)選擇數(shù)字的方法,涉及jQuery鼠標(biāo)事件的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-05-05用jQuery簡(jiǎn)化JavaScript開(kāi)發(fā)分析
我總是樂(lè)于嘗試新工具或利用節(jié)省開(kāi)發(fā)時(shí)間的資源。由于市面上存在有許多Web開(kāi)發(fā)工具,你可能很難縮小搜索范圍。2009-02-02