Author: croberts
Date: 2011-12-01 19:02:54 +0000 (Thu, 01 Dec 2011)
New Revision: 5158
Modified:
branches/noflash/cumin/resources/app.js
Log:
Now handling charts where no data was given (previously, the drawChart function would
throw an exception and nothing would show up). We are now showing an empty chart.
Modified: branches/noflash/cumin/resources/app.js
===================================================================
--- branches/noflash/cumin/resources/app.js 2011-12-01 15:31:58 UTC (rev 5157)
+++ branches/noflash/cumin/resources/app.js 2011-12-01 19:02:54 UTC (rev 5158)
@@ -605,8 +605,7 @@
y2axis: {
autoscale: true,
min:0,
- tickOptions:{formatString:'%.0f',
- formatter: y_axis_Formatter,},
+ tickOptions:{formatString:'%.0f',formatter: y_axis_Formatter,},
numberTicks:4,
},
xaxis: {
@@ -651,13 +650,24 @@
var divName = $(holder).get('id');
+ // If we have no real data to plot, add a fake coordinate to plot an empty chart
+ var needToReplot = true;
+ for (i=0; i < dataContainer['labels'].length; i++) {
+ if(dataContainer['y_coordinate_values'][i].length == 0) {
+ dataContainer['y_coordinate_values'][i] = [1,0];
+ needToReplot = false;
+ }
+ }
+
// if the chart already exists, perform a "replot()" on the chart, otherwise,
draw the chart from scratch
- if(allCharts[divName]) {
+ if(allCharts[divName] != undefined) {
for(i=0; i < allCharts[divName].series.length; i++) {
allCharts[divName].series[i].data =
dataContainer['y_coordinate_values'][i];
}
try {
-
allCharts[divName].replot({resetAxes:(!allCharts[divName].plugins.cursor._zoom.isZoomed),
axes:{y2axis:{autoscale:true,min:0,numberTicks:4,}, xaxis:{min:dataopts['xmin'] /
dataContainer['x_axis_normalizer'], max:dataopts['xmax'] /
dataContainer['x_axis_normalizer'],tickOptions:{formatString:'%.0f ' +
dataContainer['x_axis_unit_label'], formatter: x_axis_Formatter,}}}})
+ if(needToReplot) {
+
allCharts[divName].replot({resetAxes:(!allCharts[divName].plugins.cursor._zoom.isZoomed),
axes:{y2axis:{autoscale:true,min:0,numberTicks:4,tickOptions:{formatString:'%.0f',formatter:
y_axis_Formatter,}}, xaxis:{min:dataopts['xmin'] /
dataContainer['x_axis_normalizer'], max:dataopts['xmax'] /
dataContainer['x_axis_normalizer'],tickOptions:{formatString:'%.0f ' +
dataContainer['x_axis_unit_label'], formatter: x_axis_Formatter,}}}})
+ }
} catch (err) {
// this is needed in the event of the first draw for a fullpage chart
allCharts[divName] = $j.jqplot(holder,
dataContainer['y_coordinate_values'],chartOptionsObject);
@@ -666,7 +676,7 @@
allCharts[divName] = $j.jqplot(holder,
dataContainer['y_coordinate_values'],chartOptionsObject);
startChartMonitor(divName);
}
-} // end functio drawChart
+} // end function drawChart
// used in axis:tickOptions:formatter to override the default axis label formatting
x_axis_Formatter = function (format, val) {