BarChart: Print message if data is empty

This commit is contained in:
Aaron Lindsay 2017-01-10 20:41:08 -05:00
parent 007e122a4a
commit dcb921c5f5

View File

@ -11,33 +11,37 @@ module.exports = React.createClass({
* {'Label': 'bar', 'Value': 8}
* ];
*/
if (this.props.data.length < 1)
return (<div />);
var max = parseFloat(this.props.data[0].Value);
var min = parseFloat(this.props.data[0].Value);
for (var i = 0; i < this.props.data.length; i++) {
var cur = parseFloat(this.props.data[i].Value);
if (cur > max)
max = cur;
if (cur < min)
min = cur;
}
var rows = [];
for (var i = 0; i < this.props.data.length; i++) {
var rowData = this.props.data[i];
if ((max - min) == 0.0)
var percent = 100;
else if (min < 0)
var percent = 100*(parseFloat(rowData.Value)-min)/(max-min);
else
var percent = 100*parseFloat(rowData.Value)/max;
if (this.props.data.length >= 1) {
var max = parseFloat(this.props.data[0].Value);
var min = parseFloat(this.props.data[0].Value);
for (var i = 0; i < this.props.data.length; i++) {
var cur = parseFloat(this.props.data[i].Value);
if (cur > max)
max = cur;
if (cur < min)
min = cur;
}
for (var i = 0; i < this.props.data.length; i++) {
var rowData = this.props.data[i];
if ((max - min) == 0.0)
var percent = 100;
else if (min < 0)
var percent = 100*(parseFloat(rowData.Value)-min)/(max-min);
else
var percent = 100*parseFloat(rowData.Value)/max;
rows.push((
<tr key={i}>
<td style={{'width': '20%'}}>{rowData.Label + " (" + rowData.Value + ")"}</td>
<td style={{'width': '80%'}}><div style={{'width': percent + "%", 'backgroundColor': 'steelblue'}}>&nbsp;</div></td>
</tr>
));
}
} else {
rows.push((
<tr key={i}>
<td style={{'width': '20%'}}>{rowData.Label + " (" + rowData.Value + ")"}</td>
<td style={{'width': '80%'}}><div style={{'width': percent + "%", 'backgroundColor': 'steelblue'}}>&nbsp;</div></td>
</tr>
<tr><td>No data</td></tr>
));
}