Highlight all bars for Stacked bar chart with sums of bar values on top.
HTML
<script language="javascript" type="text/javascript" src="https://bitbucket.org/cleonello/jqplot/raw/b5a7796a9ebf/src/jquery.jqplot.js"></script>
<script language="javascript" type="text/javascript" src="https://bitbucket.org/cleonello/jqplot/raw/b5a7796a9ebf/src/plugins/jqplot.pointLabels.js"></script>
<script language="javascript" type="text/javascript" src="https://bitbucket.org/cleonello/jqplot/raw/b5a7796a9ebf/src/plugins/jqplot.barRenderer.js"></script>
<script language="javascript" type="text/javascript" src="https://bitbucket.org/cleonello/jqplot/raw/b5a7796a9ebf/src/plugins/jqplot.categoryAxisRenderer.js"></script>
<!-- To easily retrieve values of css parameters as margin or padding etc; as they are returned together with type of value eg. 100px, px for pixels. -->
<script language="javascript" type="text/javascript" src="https://raw.github.com/bramstein/jsizes/master/lib/jquery.sizes.js"></script>
<p>Something for testing to move slightly</p>
<div id="chart"></div>
<div id="chartTooltip" style="position: absolute; z-index: 99; display: none;"></div>
CSS
#chart{
width: 500px;
height: 500px;
left: 50px;
top: 50px
}
#chartTooltip {
font-size: 12px;
color: rgb(15%, 15%, 15%);
padding:2px;
background-color: rgba(95%, 95%, 95%, 0.8);
border: 1px solid #CCCCCC;
white-space: nowrap;
padding: 2px;
}
//jquery.jqplot.css
/*rules for the plot target div. These will be cascaded down to all plot elements according to css rules*/
.jqplot-target {
position: relative;
color: #666666;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 1em;
/* height: 300px;
width: 400px;*/
}
/*rules applied to all axes*/
.jqplot-axis {
font-size: 0.75em;
}
.jqplot-xaxis {
margin-top: 10px;
}
.jqplot-x2axis {
margin-bottom: 10px;
}
.jqplot-yaxis {
margin-right: 10px;
}
.jqplot-y2axis, .jqplot-y3axis, .jqplot-y4axis, .jqplot-y5axis, .jqplot-y6axis, .jqplot-y7axis, .jqplot-y8axis, .jqplot-y9axis, .jqplot-yMidAxis {
margin-left: 10px;
margin-right: 10px;
}
/*rules applied to all axis tick divs*/
.jqplot-axis-tick, .jqplot-xaxis-tick, .jqplot-yaxis-tick, .jqplot-x2axis-tick, .jqplot-y2axis-tick, .jqplot-y3axis-tick, .jqplot-y4axis-tick, .jqplot-y5axis-tick, .jqplot-y6axis-tick, .jqplot-y7axis-tick, .jqplot-y8axis-tick, .jqplot-y9axis-tick, .jqplot-yMidAxis-tick {
position: absolute;
white-space: pre;
}
.jqplot-xaxis-tick {
top: 0px;
/* initial position untill tick is drawn in proper place */
left: 15px;
/* padding-top: 10px;*/
vertical-align: top;
}
.jqplot-x2axis-tick {
bottom: 0px;
/* initial position untill tick is drawn in proper place */
left: 15px;
/* padding-bottom: 10px;*/
vertical-align: bottom;
}
.jqplot-yaxis-tick {
right: 0px;
/* initial position untill tick is drawn in proper place */
top: 15px;
/* padding-right: 10px;*/
text-align: right;
}
.jqplot-yaxis-tick.jqplot-breakTick {
right: -20px;
margin-right: 0px;
padding:1px 5px 1px 5px;
/* ...
JavaScript
$(document).ready(function() {
var ins = [2, 2, 3, 5];
var outs = [2, 4, 3, 5];
var swaps = [2, 2, 6, 5];
var passes = [2, 4, 6, 5];
var data = [ins, outs, swaps, passes, [3, 3, 3, 3]];
var series = [
{
label: 'IN',
pointLabels: {
labels: [2, 2, 3, 5],
location: 'w'
}},
{
label: 'OUT',
pointLabels: {
labels: [2, 4, 3, 5],
location: 'e'
}},
{
label: 'SWAP',
pointLabels: {
labels: [2, 2, 6, 5],
location: 'n'
}},
{
label: 'PASS',
pointLabels: {
labels: [2, 4, 6, 5],
location: 's'
}},
{
label: 'INVISIBLE',
pointLabels: {
labels: ['∑ 8', '∑ 12', '∑ 18', '∑ 20']
},
show: false,
shadowAngle: 90,
//for horizontal use (180 istead of 90)
rendererOptions: {
shadowDepth: 25,
shadowOffset: 2.5,
shadowAlpha: 0.01
}}
];
var ticks = ['Oi', 'Bike', 'Car', 'Truck'];
var plot = $.jqplot('chart', data, {
stackSeries: true,
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
rendererOptions: {
barMargin: 20
//for horizontal uncomment this
// ,barDirection: 'horizontal'
},
pointLabels: {
show: true,
stackedValue: false,
location: 's'
}
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
//for horiozontal use the below instead
/*
yaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
*/
},
legend: {
show: true,
...