As we experiment, we come across the option to pass the data points from the cursor tooltip to the legend. We revisit the chart we just worked on, and save it as a new file, 1168_06_05.html
:
<script src="../js/jqplot.cursor.min.js"></script> <script src="../js/jqplot.canvasTextRenderer.min.js"></script> <script src="../js/jqplot.canvasAxisTickRenderer.min.js"></script> <script src="../js/jqplot.canvasAxisLabelRenderer.min.js"></script>
showTooltip
to false
so that we don't show data points in multiple places. We set showVerticalLine
to true
. By connecting the cursor to the legend, values will only appear when the cursor crosses data points. When our vertical line crosses a data point, the values will appear in the legend. So, showVerticalLine
must be set in order for this to work: cursor: {
show: true,
showTooltip: false,
showVerticalLine: true,
showCursorLegend
, to true
. By default, the format string for the cursor legend is %s x:%s, y:%s
. We just want the label and the dollar amount. Since the label, the x
value, and the y
value are passed in this order, we wrap the date in a span to hide it when it is displayed:showCursorLegend: true, cursorLegendFormatString: '%s <span class="hidden">%s</span><span class="right">%s</span>' }, ...
labelRenderer
under axesDefaults
, so it will affect all the axes:axesDefaults: {
labelRenderer: $.jqplot.CanvasAxisLabelRenderer
},
axes:{
...
<div id="revenueProfitChart" style="width:750px;"></div> <style> table.jqplot-legend { right: -65px; min-width: 165px; } table.jqplot-legend td { border: 0;} td.jqplot-cursor-legend-swatch { width: 24px;} td.jqplot-cursor-legend-label { padding-left: 10px;} td.jqplot-cursor-legend-label .right { float:right; padding-right: 10px; } </style>
We move our cursor over April, and though the cursor is not actually on the data points, the vertical line intersects the points. We can see that our legend shows the dollar amount for each data point in April in the following screenshot:
We have created several charts using the cursor plugin in different ways. We'll let Roshan and the rest of the management team try them out and see which works best for them.
3.133.127.37