Date 谷歌图表,带日期范围过滤器的折线图
我使用的是折线图,通过单击图例可以选择性地查看图表上的Y系列数据。类似于谷歌金融图表的东西,它允许你在图表上添加不同的股票 我想添加一个日期范围过滤器,如本例中注释图表底部所示: 但它只是显示一个空白屏幕 以下是我的折线图代码:Date 谷歌图表,带日期范围过滤器的折线图,date,charts,filter,range,line,Date,Charts,Filter,Range,Line,我使用的是折线图,通过单击图例可以选择性地查看图表上的Y系列数据。类似于谷歌金融图表的东西,它允许你在图表上添加不同的股票 我想添加一个日期范围过滤器,如本例中注释图表底部所示: 但它只是显示一个空白屏幕 以下是我的折线图代码: <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualizat
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['annotationchart']}]}"></script>
<script type='text/javascript'>
google.load("visualization", "1", {packages:["corechart"]});
google.load('visualization', '1', { packages : ['controls'] } );
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Date', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
['2014', 1230, 40]
]);
var options = {
width: 900,
height: 600,
title: 'Company Performance',
displayAnnotations: true,
series: series
}
var chart = new google.visualization.LineChart(document.getElementById('chart_div')); //line chart
chart.draw(data, options);
var columns = [];
var series = {};
for (var i = 0; i < data.getNumberOfColumns(); i++) {
columns.push(i);
if (i > 0) {
series[i - 1] = {};
}
}
google.visualization.events.addListener(chart, 'select', function () {
var sel = chart.getSelection();
// if selection length is 0, we deselected an element
if (sel.length > 0) {
// if row is null, we clicked on the legend
if (sel[0].row == null) {
var col = sel[0].column;
if (columns[col] == col) {
// hide the data series
columns[col] = {
label: data.getColumnLabel(col),
type: data.getColumnType(col),
calc: function () {
return null;
}
};
// grey out the legend entry
series[col - 1].color = '#CCCCCC';
}
else {
// show the data series
columns[col] = col;
series[col - 1].color = null;
}
var view = new google.visualization.DataView(data);
view.setColumns(columns);
chart.draw(view, options);
}
}
});
}
</script>
</head>
<body>
<div id='chart_div' style='width: 900px; height: 600px;'></div>
</body>
</html>
load(“可视化”、“1”、{packages:[“corechart”]});
load('visualization','1',{packages:['controls']});
setOnLoadCallback(drawChart);
函数绘图图(){
var data=google.visualization.arrayToDataTable([
[“日期”、“销售”、“费用”],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
['2014', 1230, 40]
]);
变量选项={
宽度:900,
身高:600,
标题:“公司业绩”,
是的,
系列:系列
}
var chart=new google.visualization.LineChart(document.getElementById('chart_div'));//折线图
图表绘制(数据、选项);
var列=[];
var级数={};
对于(var i=0;i0){
系列[i-1]={};
}
}
google.visualization.events.addListener(图表,'select',函数(){
var sel=chart.getSelection();
//如果选择长度为0,则取消选择一个元素
如果(选择长度>0){
//如果行为空,则单击图例
如果(sel[0]。行==null){
var col=sel[0]。列;
if(列[col]==col){
//隐藏数据系列
列[col]={
标签:data.getColumnLabel(col),
类型:data.getColumnType(col),
计算:函数(){
返回null;
}
};
//灰色显示图例条目
系列[col-1]。颜色='#cccc';
}
否则{
//显示数据系列
列[col]=col;
系列[col-1]。颜色=null;
}
var view=newgoogle.visualization.DataView(数据);
view.setColumns(列);
图表绘制(视图、选项);
}
}
});
}
您应该使用带有线条图图表包装器和daterangefilter的仪表板作为控制包装器,而不是像您那样初始化图表(您甚至不调用daterangefilter)