正如标题所示,我想显示一个Google图表,省略了我的数据表的一列。我的表格结构如下:
['2016-01-05 12:45:05', 1.187, 20.375, 45.375],
['2016-01-05 13:00:04', 1.687, 21.437, 43.937],
['2016-01-05 13:15:04', 2.062, 22.062, 43.25],
有四列,但我只想在图表中显示第一,第三和第四列。
我的Google图表摘录如下:
def print_graph_script(table):
# google chart snippet
chart_code="""
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Time', 'Temp1', 'Temp2', 'Temp3'], %s ]);
var options = {
animation:{"startup": true, duration: 1500, easing: 'out', },
title: 'Temperature',
showAxisLines:true,
hAxis: {
title: '',
slantedText:true,
slantedTextAngle:90,
textStyle: {fontSize: '12'}
},
vAxis: {
title: '',
textStyle: {fontSize: '12'}
},
series: {
0: { color: '#333333' },
1: { color: '#75baff' },
2: { color: '#eba314' },
}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>"""
print chart_code % (table)
有什么想法吗?提前致谢
答案 0 :(得分:0)
为什么不像
那样过滤表格table_filtered = [ [row[0], row[2], row[3]] for row in table]
并将table_filtered
传递给印刷品
答案 1 :(得分:0)
我不确定为什么,使用两种观点购买似乎有效 我只使用一个视图就收到了与评论相同的错误 在这里,我创建视图1,隐藏列,然后从视图1创建视图2.
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Time', 'Col 1', 'Col 2', 'Col 3'],
['2016-01-05 12:45:05', 1.187, 20.375, 45.375],
['2016-01-05 13:00:04', 1.687, 21.437, 43.937],
['2016-01-05 13:15:04', 2.062, 22.062, 43.25],
]);
var dataView1 = new google.visualization.DataView(data);
dataView1.hideColumns([1]);
var dataView2 = new google.visualization.DataView(dataView1);
var options = {
animation: {
startup: true,
duration: 1500,
easing: 'out'
},
title: 'Temperature',
showAxisLines: true,
hAxis: {
title: '',
slantedText:true,
slantedTextAngle:90,
textStyle: {fontSize: '12'}
},
vAxis: {
title: '',
textStyle: {fontSize: '12'}
},
series: {
0: { color: '#333333' },
1: { color: '#75baff' },
2: { color: '#eba314' },
}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(dataView2, options);
}
&#13;
<script src="https://www.google.com/jsapi"></script>
<div id="chart_div"></div>
&#13;