这是您的问题的解决方法:JsFiddle 链接
这是可以解决您的问题的代码,请对此代码进行更改或抓取重要部分并将其放入您的代码中。
$(document).ready(function () {
var s1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
var s2 = [5, 15, 15, 30, 45, 60, 35, 49, 75, 95];
var ticks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var seriesData = [], seriesIndex = 0;
function storeSeriesData(){
seriesData[seriesIndex] = this.data;
seriesIndex = seriesIndex + 1;
}
$.jqplot.LabelFormatter = function(format, val){
var result, pointVal = -1;
if(seriesIndex > 1){
for(var i = 0; i < seriesData[seriesIndex - 1].length; i++){
var tempData = seriesData[seriesIndex - 1][i];
if(tempData[1] == val){
break;
}
}
pointVal = seriesData[seriesIndex - 2][i];
result = val + "("+ parseFloat(val/pointVal[1] * 100).toFixed(1) + "%)";
}
else{
result = val;
}
return result;
};
$.jqplot.preDrawSeriesHooks.push(storeSeriesData);
var plot1 = $.jqplot('chart1', [s1, s2], {
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
rendererOptions: {
barPadding: 15,
barWidth: 25
},
pointLabels: {
show:true,
formatString: "%#.1f",
formatter: $.jqplot.LabelFormatter
}
},
grid: {
drawBorder: true,
background: '#ffffff'
},
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: {
markSize: 4
}
},
axes: {
xaxis: {
pad: -1.05,
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks,
tickOptions: {
showGridline: true
}
},
yaxis: {
pad: 1.05,
tickOptions: {
formatString: '%d',
showGridline: true
}
}
}
});
});