<html>
<head>
<title>Dashboard Evelien</title>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load the Visualization API and the controls package.
google.charts.load('current', {'packages':['corechart', 'controls', 'table']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawDashboard);
// Callback that creates and populates a data table,
// instantiates a dashboard, a range slider and a pie chart,
// passes in the data and draws it.
function drawDashboard() {
// Create our data table.
var data = google.visualization.arrayToDataTable([
['geo_Stad', 'Name', 'Leningdelen', 'Hypotheek', 'Straat', 'Woonplaats', 'Datum_start', 'Datum_eind', 'Mv', 'looptijd'],
['Netherlands, Amsterdam', 'Aap' , 5, 500000, 'Kalverstraat', 'Amsterdam', new Date(2014, 3, 22), new Date(2016, 2, 28), 'm', 123],
['Netherlands, Rotterdam', 'Noot', 1, 70000, 'Beursplein', 'Rotterdam', new Date(2014, 10, 11), new Date(2017, 3, 20), 'm', 234],
['Netherlands, Rotterdam', 'Mies', 3, 300000, 'Stationsplein', 'Rotterdam', new Date(2013, 10, 1), new Date(2013, 12, 23), 'v', 564],
['Netherlands, Amsterdam', 'Wim' , 2, 222222, 'Dorpsstraat', 'Amsterdam', new Date(2010, 1, 2), new Date(2016, 10, 23), 'm', 456],
['Netherlands, Amsterdam', 'Zus' , 7, 600000, 'Stationsplein', 'Amsterdam', new Date(2007, 5, 22), new Date(2009, 2, 2), 'v', 385],
['Netherlands, Rotterdam', 'Jet' , 2, 100000, 'Dorpsstraat', 'Rotterdam', new Date(2014, 7, 7), new Date(2015, 2, 16), 'v', 964],
['Netherlands, Rotterdam', 'Teun', 1, 85670, 'Kerkstraat', 'Rotterdam', new Date(2014, 3, 22), new Date(2016, 11, 12), 'm', 356],
['Netherlands, Utrecht', 'Gijs', 1, 53400, 'Stationsstraat', 'Utrecht', new Date(2014, 3, 22), new Date(2016, 6, 18), 'm', 356],
['Netherlands, Utrecht', 'Does', 1, 77200, 'Vreeburg', 'Utrecht', new Date(2014, 3, 22), new Date(2016, 8, 8), 'm', 768],
['Netherlands', 'Does1', 0, 0, 'Amsterdam', 'Nederland', new Date(2014, 3, 22), new Date(2016, 8, 8), '', 467],
['Netherlands', 'Does2', 0, 0, 'Rotterdam', 'Nederland', new Date(2014, 3, 22), new Date(2016, 8, 8), '', 563],
['Netherlands', 'Does3', 0, 0, 'Utrecht', 'Nederland', new Date(2014, 3, 22), new Date(2016, 8, 8), '', 467],
['Netherlands', 'Does4', 0, 0, 'Nederland', null, new Date(2014, 3, 22), new Date(2016, 8, 8), '', 963]
]);
// Create a dashboard.
var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div'));
// Create a range slider, passing some options
var donutRangeSlider = new google.visualization.ControlWrapper({
'controlType': 'NumberRangeFilter',
'containerId': 'filter_div',
'options': {
'filterColumnLabel': 'Leningdelen'
}
});
var tableE = new google.visualization.ChartWrapper({
'chartType': 'Table',
'containerId': 'tableE_div',
'view': {'rows' : data.getFilteredRows([{column: 2, minValue: 1}])},
'options': {
'showRowNumber': 'true',
'width': '100%',
'height': '33%',
}
});
// Create a pie chart, passing some options
var pieChart = new google.visualization.ChartWrapper({
'chartType': 'PieChart',
'containerId': 'chart_div',
'view': {'columns': [1, 2],
'rows' : data.getFilteredRows([{column: 2, minValue: 1}])},
'options': {
'width': 400,
'height': 300,
'pieSliceText': 'value',
'legend': 'right'
}
});
// Create a bar chart, passing some options
var barChart = new google.visualization.ChartWrapper({
'chartType': 'BarChart',
'containerId': 'chartB_div',
'view': {'columns': [1, 2],
'rows' : data.getFilteredRows([{column: 2, minValue: 1}])},
'options': {
'width': 500,
'height': 300,
'legend': 'right'
}
});
// Establish dependencies, declaring that 'filter' drives 'pieChart',
// so that the pie chart will only display entries that are let through
// given the chosen slider range.
dashboard.bind(donutRangeSlider, [tableE, pieChart, barChart]);
// Draw the dashboard.
dashboard.draw(data);
}
</script>
</head>
<body>
<!--Div that will hold the dashboard-->
<div id="dashboard_div">
<table class="columns">
<tr>
<td><div id="filter_div" style="border: 1px solid #ccc"></div></td>
</tr>
<tr>
<td><div id="chart_div" style="border: 1px solid #ccc"></div></td>
<td><div id="chartB_div" style="border: 1px solid #ccc"></div></td>
</tr>
</table>
<table>
<tr>
<td><div id="tableE_div" style="border: 1px solid #ccc"></div></td>
</tr>
</table>
</div>
</body>
</html>
Hi,
I am trying to make a dashboard with many differend graphs, but I cannot solve the issue 'Invalid row index 5. Should be in the range [0-4].'
Now I have a very simple dashboard, it works when I use only the data columns the 2 simple graphs need. But I want more graphs with other columns. When I add more columns to the data, the error pops up. I think I need a ready Listener somewhere in the code, but I tried so many times using the answeres for others, but without success.
So will you please complete my code with a ready listener so the error will be solved? Thanks !
a 'ready' listener will not resolve the problem
the problem stems from...
'rows' : data.getFilteredRows([{column: 2, minValue: 1}])}
once the dashboard is drawn and the filter value changes,
there are rows that exist in the data, that do not exist in the dashboard
so getFilteredRows is returning more rows than the dashboard has access to
thus, the error is thrown --> Invalid row index
to correct, just use an overall DataView to draw the dashboard
var view = new google.visualization.DataView(data);
view.setRows(data.getFilteredRows([{column: 2, minValue: 1}]));
dashboard.draw(view);
see following working snippet...
google.charts.load('current', {'packages':['corechart', 'controls', 'table']});
google.charts.setOnLoadCallback(drawDashboard);
function drawDashboard() {
var data = google.visualization.arrayToDataTable([
['geo_Stad', 'Name', 'Leningdelen', 'Hypotheek', 'Straat', 'Woonplaats', 'Datum_start', 'Datum_eind', 'Mv', 'looptijd'],
['Netherlands, Amsterdam', 'Aap' , 5, 500000, 'Kalverstraat', 'Amsterdam', new Date(2014, 3, 22), new Date(2016, 2, 28), 'm', 123],
['Netherlands, Rotterdam', 'Noot', 1, 70000, 'Beursplein', 'Rotterdam', new Date(2014, 10, 11), new Date(2017, 3, 20), 'm', 234],
['Netherlands, Rotterdam', 'Mies', 3, 300000, 'Stationsplein', 'Rotterdam', new Date(2013, 10, 1), new Date(2013, 12, 23), 'v', 564],
['Netherlands, Amsterdam', 'Wim' , 2, 222222, 'Dorpsstraat', 'Amsterdam', new Date(2010, 1, 2), new Date(2016, 10, 23), 'm', 456],
['Netherlands, Amsterdam', 'Zus' , 7, 600000, 'Stationsplein', 'Amsterdam', new Date(2007, 5, 22), new Date(2009, 2, 2), 'v', 385],
['Netherlands, Rotterdam', 'Jet' , 2, 100000, 'Dorpsstraat', 'Rotterdam', new Date(2014, 7, 7), new Date(2015, 2, 16), 'v', 964],
['Netherlands, Rotterdam', 'Teun', 1, 85670, 'Kerkstraat', 'Rotterdam', new Date(2014, 3, 22), new Date(2016, 11, 12), 'm', 356],
['Netherlands, Utrecht', 'Gijs', 1, 53400, 'Stationsstraat', 'Utrecht', new Date(2014, 3, 22), new Date(2016, 6, 18), 'm', 356],
['Netherlands, Utrecht', 'Does', 1, 77200, 'Vreeburg', 'Utrecht', new Date(2014, 3, 22), new Date(2016, 8, 8), 'm', 768],
['Netherlands', 'Does1', 0, 0, 'Amsterdam', 'Nederland', new Date(2014, 3, 22), new Date(2016, 8, 8), '', 467],
['Netherlands', 'Does2', 0, 0, 'Rotterdam', 'Nederland', new Date(2014, 3, 22), new Date(2016, 8, 8), '', 563],
['Netherlands', 'Does3', 0, 0, 'Utrecht', 'Nederland', new Date(2014, 3, 22), new Date(2016, 8, 8), '', 467],
['Netherlands', 'Does4', 0, 0, 'Nederland', null, new Date(2014, 3, 22), new Date(2016, 8, 8), '', 963]
]);
var view = new google.visualization.DataView(data);
view.setRows(data.getFilteredRows([{column: 2, minValue: 1}]));
var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div'));
var donutRangeSlider = new google.visualization.ControlWrapper({
'controlType': 'NumberRangeFilter',
'containerId': 'filter_div',
'options': {
'filterColumnLabel': 'Leningdelen'
}
});
var tableE = new google.visualization.ChartWrapper({
'chartType': 'Table',
'containerId': 'tableE_div',
'options': {
'showRowNumber': 'true',
'width': '100%',
'height': '33%',
}
});
var pieChart = new google.visualization.ChartWrapper({
'chartType': 'PieChart',
'containerId': 'chart_div',
'view': {
'columns': [1, 2]
},
'options': {
'width': 400,
'height': 300,
'pieSliceText': 'value',
'legend': 'right'
}
});
var barChart = new google.visualization.ChartWrapper({
'chartType': 'BarChart',
'containerId': 'chartB_div',
'view': {
'columns': [1, 2]
},
'options': {
'width': 500,
'height': 300,
'legend': 'right'
}
});
dashboard.bind(donutRangeSlider, [tableE, pieChart, barChart]);
dashboard.draw(view);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="dashboard_div">
<table class="columns">
<tr>
<td><div id="filter_div" style="border: 1px solid #ccc"></div></td>
</tr>
<tr>
<td><div id="chart_div" style="border: 1px solid #ccc"></div></td>
<td><div id="chartB_div" style="border: 1px solid #ccc"></div></td>
</tr>
</table>
<table>
<tr>
<td><div id="tableE_div" style="border: 1px solid #ccc"></div></td>
</tr>
</table>
</div>
I'm looking to draw a fairly simple google LineChart, but I'd like to have horizontal coloured bands across the chart area, to indicate low/middle/high values.
Looking at the chart API, it does not appear to be possibly directly, as chartArea.backgroundColor appears to be the only value I can set.
Being aware that this appears to be a limitation of the charts, is it possible to recreate this any other way, through any other methods or javascript wizardry?
Below is an example of what sort of effect I'm looking to produce.
Thanks in advance.
using a ComboChart
with seriesType: 'area'
and isStacked: true
you can define as many ranges as needed
visibleInLegend: false hides the area series from the legend
then you can set a custom type: for the series you want to track,
such as 'line', in the following working snippet...
google.charts.load('current', {
callback: function () {
var dataTable = new google.visualization.DataTable({
cols: [
{label: 'Time', type: 'number'},
{label: 'Low', type: 'number'},
{label: 'Avg', type: 'number'},
{label: 'High', type: 'number'},
{label: 'Dogs', type: 'number'}
],
rows: [
{c:[{v: 0}, {v: 25}, {v: 50}, {v: 25}, {v: 0}]},
{c:[{v: 5}, {v: 25}, {v: 50}, {v: 25}, {v: 24}]},
{c:[{v: 10}, {v: 25}, {v: 50}, {v: 25}, {v: 20}]},
{c:[{v: 15}, {v: 25}, {v: 50}, {v: 25}, {v: 48}]},
{c:[{v: 20}, {v: 25}, {v: 50}, {v: 25}, {v: 53}]},
{c:[{v: 25}, {v: 25}, {v: 50}, {v: 25}, {v: 61}]},
{c:[{v: 30}, {v: 25}, {v: 50}, {v: 25}, {v: 63}]},
{c:[{v: 40}, {v: 25}, {v: 50}, {v: 25}, {v: 66}]},
{c:[{v: 45}, {v: 25}, {v: 50}, {v: 25}, {v: 70}]},
{c:[{v: 50}, {v: 25}, {v: 50}, {v: 25}, {v: 75}]},
{c:[{v: 55}, {v: 25}, {v: 50}, {v: 25}, {v: 78}]},
{c:[{v: 60}, {v: 25}, {v: 50}, {v: 25}, {v: 80}]},
{c:[{v: 65}, {v: 25}, {v: 50}, {v: 25}, {v: 85}]},
{c:[{v: 70}, {v: 25}, {v: 50}, {v: 25}, {v: 90}]}
]
});
var options = {
chartArea: {
width: '60%'
},
hAxis: {
ticks: [0, 15, 30, 45, 60],
title: 'Time'
},
isStacked: true,
series: {
// low
0: {
areaOpacity: 0.6,
color: '#FFF59D',
visibleInLegend: false
},
// avg
1: {
areaOpacity: 0.6,
color: '#A5D6A7',
visibleInLegend: false
},
// high
2: {
areaOpacity: 0.6,
color: '#EF9A9A',
visibleInLegend: false
},
// dogs
3: {
color: '#01579B',
type: 'line'
}
},
seriesType: 'area',
title: 'Example',
vAxis: {
ticks: [0, 25, 50, 75, 100],
title: 'Popularity'
}
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(dataTable, options);
},
packages:['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
Trying to work with Google charts and ended up with a range slider thru few code snippets provided by developer docs.
<https://jsfiddle.net/hari41980/gsvr18hw/11/>
Now I need someone to help me on getting the date range from date to TIME.
Expected:expected output
Regards
just need to set the desired format in the options for the slider...
'ui': {
'format': {
'pattern': 'h:mm a'
},
'labelStacking': 'vertical'
}
see following example...
google.charts.load('current', {
callback: function () {
var dashboard = new google.visualization.Dashboard(
document.getElementById('programmatic_dashboard_div'));
var programmaticSlider = new google.visualization.ControlWrapper({
'controlType': 'DateRangeFilter',
'containerId': 'programmatic_control_div',
'options': {
'filterColumnLabel': 'Time Stamp',
'ui': {
'format': {
'pattern': 'h:mm a'
},
'labelStacking': 'vertical'
}
}
});
var programmaticChart = new google.visualization.ChartWrapper({
'chartType': 'AreaChart',
'containerId': 'programmatic_chart_div',
'options': {
'width': 600,
'height': 300,
'legend': 'none',
}
});
var data = google.visualization.arrayToDataTable([
['Time Stamp', 'Bulk'],
[new Date(2014, 9, 15, 10, 30) , 5],
[new Date(2014, 9, 15, 11, 30) , 10],
[new Date(2014, 9, 15, 12, 30) , 15],
[new Date(2014, 9, 15, 13, 30) , 5],
[new Date(2014, 9, 15, 14, 30) , 10],
[new Date(2014, 9, 15, 15, 30) , 8],
[new Date(2014, 9, 15, 16, 30) , 12],
[new Date(2014, 9, 15, 17, 30) , 15],
[new Date(2014, 9, 15, 18, 30) , 25]
]);
dashboard.bind(programmaticSlider, programmaticChart);
dashboard.draw(data);
},
packages: ['corechart', 'controls']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="programmatic_control_div"></div>
<div id="programmatic_chart_div"></div>
options: {"title":"Overall Stats","height":230,"legend":{"position":"in"},"hAxis":{"title":"Division"}},
I have this as my options for my google column chart but this displays "Division" on both my vertical and horizontal axis and removes all the labels on the hAxis. Can anyone tell me why this is happening?
is there more you can share?
seems to work fine here...
google.charts.load('current', {
callback: function () {
var data = new google.visualization.DataTable();
data.addColumn('timeofday', 'Time of Day');
data.addColumn('number', 'Motivation Level');
data.addColumn('number', 'Energy Level');
data.addRows([
[{v: [8, 0, 0], f: '8 am'}, 1, .25],
[{v: [9, 0, 0], f: '9 am'}, 2, .5],
[{v: [10, 0, 0], f:'10 am'}, 3, 1],
[{v: [11, 0, 0], f: '11 am'}, 4, 2.25],
[{v: [12, 0, 0], f: '12 pm'}, 5, 2.25],
[{v: [13, 0, 0], f: '1 pm'}, 6, 3],
[{v: [14, 0, 0], f: '2 pm'}, 7, 4],
[{v: [15, 0, 0], f: '3 pm'}, 8, 5.25],
[{v: [16, 0, 0], f: '4 pm'}, 9, 7.5],
[{v: [17, 0, 0], f: '5 pm'}, 10, 10],
]);
new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
dataTable: data,
options: {"title":"Overall Stats","height":230,"legend":{"position":"in"},"hAxis":{"title":"Division"}}
}).draw();
},
packages: ['corechart', 'controls']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
I am currently testing google charts and having difficulty in specifying my own custom tooltips.
my data is declared as below
var data = new google.visualization.DataTable();
data.addColumn('number', 'X');
data.addColumn('number', 'Dogs');
data.addColumn('number', 'Cats');
data.addColumn({type: 'string', role: 'tooltip', p: {'html':true}});
data.addRows([0, 0, 0, 'hello'], [1, 10, 5, 'hello'],
[2, 23, 15, 'hello'],[3, 17, 9, 'hello'], [4, 18, 10, 'hello'],
[5, 9, 5, 'hello'],
see this jsFiddle http://jsfiddle.net/SecretSquirrel/rbwyhx1q/
It appears the custom tooltip is only affecting the first data column?
I thought it was pretty limited to only allow 1 tooltip per row, but if this is only 1 tooltip for the first column this is really quite useless.
Well you have to add another tooltip column for your second graft.
google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'X');
data.addColumn('number', 'Dogs');
data.addColumn({type: 'string', role: 'tooltip', p: {'html':true}});
data.addColumn('number', 'Cats');
data.addColumn({type: 'string', role: 'tooltip', p: {'html':true}});
data.addRows([
[0, 0,'custom', 0, 'hello'], [1, 10,'custom', 5, 'hello'], [2, 23,'custom', 15, 'hello'],
[3, 17,'custom', 9, 'hello'], [4, 18,'custom', 10, 'hello'], [5, 9,'custom', 5, 'hello'],
[6, 11,'custom', 3, 'hello'], [7, 27,'custom', 19, 'hello'], [8, 33,'custom', 25, 'hello'],
[9, 40,'custom', 32, 'hello'], [10, 32,'custom', 24, 'hello'], [11, 35,'custom', 27, 'hello'],
[12, 30,'custom', 22, 'hello'], [13, 40,'custom', 32, 'hello'], [14, 42,'custom', 34, 'hello'],
[15, 47,'custom', 39,'hello'], [16, 44,'custom', 36,'hello'], [17, 48,'custom', 40, 'hello'],
[18, 52,'custom', 44,'hello'], [19, 54,'custom', 46,'hello'], [20, 42,'custom', 34, 'hello'],
[21, 55,'custom', 47,'hello'], [22, 56,'custom', 48,'hello'], [23, 57,'custom', 49,'hello']
]);
var options = {
width: 1000,
height: 563,
hAxis: {
title: 'Time'
},
vAxis: {
title: 'Popularity'
},
series: {
1: {curveType: 'function'}
}
};
var chart = new google.visualization.LineChart(document.getElementById('ex2'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}"></script>
<div id="ex2"></div>