从2015年11月30日到2019年2月29日,我有很多价值。由于2月29日到4月11日是零,然后4月11日之后的新值。如果我使用“日期”类型的轴,我将有一个很大的空间beetwen 2月29日和11日4月11日:http://white-fund.com/#roiPage (左图表)如果我使用字符串类型的轴,我将没有分组(在1个元素中没有几天),也没有按月显示。
我需要日期格式,分组,没有空格,就像我在Excel中得到的那样:http://white-fund.com/pictures/total_roi.png
代码:
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'x');
data.addColumn('number', 'ROI per day');
data.addColumn('number', 'Total ROI');
<?php
$db = new db();
$ROIRows = $db->select("roi");
if($ROIRows) foreach ($ROIRows as $ROIRow) {
echo "data.addRow([new Date(\"$ROIRow[date_time]\"), ". ($ROIRow['roi']/100) .", ". ($ROIRow['total_roi']/100) ."]);";
}
?>
var formatter = new google.visualization.NumberFormat({
pattern: '#,###%',
fractionDigits: 2
});
formatter.format(data, 1);
formatter.format(data, 2);
// Create and draw the visualization.
new google.visualization.ComboChart(document.getElementById('chart_div')).
draw(data, {curveType: "function", width: 540, height: 290,
vAxes:{
0: {title:'ROI per day', format: 'percent'},
1: {title:'Total ROI', format: 'percent'}
},
series:{
0:{targetAxisIndex:0, type: 'bars', logScale:false},
1:{targetAxisIndex:1, type: 'line', pointSize:7, logScale:false},
},
seriesType: 'bars'
}
);
}
google.charts.setOnLoadCallback(drawChart);另一个问题:如何在浮点型中显示百分比,而不是整型?我尝试使用格式化程序,但它显示272.52%为273%。
谢谢!
发布于 2016-04-13 19:58:13
要填充空白,请在您的configuration options中添加interpolateNulls: true ...
至于数字格式,请尝试此模式--> '#,##0.00%'
然后失去fractionDigits: 2
https://stackoverflow.com/questions/36594936
复制相似问题