Since this chart will be in a confined space, we will turn off the ticks and label on the y axis to increase the amount of area in the chart. We will use the same plugins as before, but we will also include the pointLabels
plugin this time:
... <script src="../js/jqplot.pointLabels.min.js"></script> ... var rev_category = $.jqplot ('rev_category', [ [dvds[11]], [cds[11]], [software[11]], [digital[11]], [tvs[11]], [computers[11]], [consoles[11]], [dvd_players[11]], [media_streamers[11]]], ...
edgeTolerance
option for the pointLabels
option. In the previous charts, the point labels disappeared when they got too close to the edge of the plot. Our workaround was to add padding to the y axis. With edgeTolerance
, if our point label is too long, it will continue beyond the edge of the plot. If it passes our newly set threshold, jqPlot will turn off the label: seriesDefaults: {
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true, edgeTolerance: -75 },
rendererOptions: {
barDirection: 'horizontal',
barPadding: 10,
barMargin: 10,
shadow: false
}
},
y
value for our point labels. We do away with the legend and set labels
to the category name for the pointLabels
option. The labels
option takes an array because it expects a label for each point on the data series. Since we only have one data point per series, our arrays will also have one element:series: [ { label: 'DVDs/Blu-ray', color: '#FF0000', pointLabels:{ labels:['DVDs/Blu-ray'] } }, { label: 'Music CDs', color: '#0BBBE0', pointLabels:{ labels:['Music CDs'] } }, { label: 'Software', color: '#0000FF', pointLabels:{ labels:['Software'] } }, { label: 'Digital', color: '#555', pointLabels:{ labels:['Digital'] } }, { label: 'TVs', color: '#FF960C', pointLabels:{ labels:['TVs'] } }, { label: 'Computers', color: '#00007F', pointLabels:{ labels:['Computers'] } }, { label: 'Game Consoles', pointLabels:{ labels:['Game Consoles'] } }, { label: 'DVD Players', color: '#56C2B2', pointLabels:{ labels:['DVDs/Blu-ray Players'] } }, { label: 'Media Streamers', color: '#62FF0D', pointLabels:{ labels:['Media Streamers'] } }, ],
fontSize
to 10pt
for the x axis: axes:{
xaxis:{ label: 'Revenue in Dollars',
tickOptions: {
formatString: "$%'d",
fontSize: '10pt'
}
},
tickOptions
are showGridline
, showMark
, and showLabel
. We want to turn off all three so we use show
and set it to false
. We hide the axis label by setting showLabel
to false
:yaxis: { renderer: $.jqplot.CategoryAxisRenderer, tickOptions: { show: false }, showLabel: false } } }); }); </script>
<h1>Dashboard</h1> <div id="monthly_rev" class="dashboard block"> <h2>Last Month's Revenue by Product Category</h2> <div id="rev_category" style="width:200px; height:400px;"></div> </div> <style> .jqplot-point-label { font-size: .75em; z-index: 2; white-space: nowrap; border: 1.5px solid #aaaaaa; padding: 1px 2px; background-color: #eeccdd; } </style>
We load our new dashboard, and the chart works as we intended. The changes to our styles make the chart easier to view. Also, it is small enough, so we can place several other charts next to it, and it will all fit on one screen.
With our restrictions, we could not fit all these data series in a vertical bar chart, so this is one of the times that horizontal charts shine. Also, we see that most of our point labels stay inside our plot, but the label for Computers and Game Consoles extend beyond the chart. This is a compromise we made; either the labels extend beyond the chart or our bars are shorter and harder to see if we add padding.
As we think about what might come next, Calvin walks in the office with a woman. "This is Sara. She wanted to stop by and meet you two." We introduce ourselves and you mention that we just wrapped up the dashboard prototype.
3.133.123.34