I'm trying to draw a barchart with chart range filter with the script and code bellow, but i'm getting 2 errors 1-One or more participants failed to draw()× 2-The filter cannot operate on a column of type string. Column type must be one of: number, date, datetime or timeofday. Column role must be domain, and correlate to a continuous axis
for the second error, the data is clear as you see in the code below
<div id="dashboard" class="container-fluid" style="height:100%">
<div id="chart_div" style="height:99%"></div>
<div id="filter-range" style="height:1%"></div>
</div>
<script type="text/javascript">
google.charts.load('current', { packages: ['corechart', 'controls'] });
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Name', 'Donuts eaten', 'Donuts eaten'],
['Michael', 5, 6],
['Elisa', 7, 6],
['Robert', 3, 7],
['John', 2, 8],
['Jessica', 6, 9],
['Aaron', 1, 20],
['Margareth', 8, 8]
]);
var rangeFilter = new google.visualization.ControlWrapper({
controlType: 'ChartRangeFilter',
containerId: 'filter-range',
options: {
filterColumnIndex: 0,
ui: {
chartType: 'ColumnChart',
chartOptions: {
height: 40,
colors: ['#ff7900', '#50be87'],
chartArea: {
width: '100%',
height: '100%',
top: 0,
left: 0,
right: 0,
bottom: 0
}
}
}
}
});
var chart = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
options: {
width: '100%',
height: 450,
legend: {
alignment: 'end',
position: 'top'
},
animation: {
duration: 500,
easing: 'in',
startup: true
},
chartArea: {
top: 36,
left: 36,
right: 18,
bottom: 36
},
isStacked: true,
bar: { groupWidth: '95%' },
colors: ['#ff7900', '#50be87']
}
});
var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard'));
dashboard.bind(rangeFilter, chart);
dashboard.draw(data);
}
</script>```
the main issue is from error #2.
the chart range filter will not operate on a string column, in this case, the
'Name'column.because the purpose is to filter on a range of values; number, date, etc...
as a work around, we can change the first column to be numeric.
then use object notation to set the numeric value (
v:), and the formatted value (f:).this will correct the error and the tooltip shown when hovering the column.
Michael will appear, instead of 1.
in order to get the names to appear under the columns,
we need to add the
ticksoption to thehAxis,using the same object notation.
then reference in the options...
next,
ColumnChartis not a validchartTypeoption for the range filter.valid types include:
'AreaChart','LineChart','ComboChart'or'ScatterChart'as such, we can use
'ComboChart', then setseriesTypeto'bars'as for the animation option, when using option:
startup: trueon a dashboard, there is a bug that causes an error to be thrown.
a workaround for this involves drawing the chart with initial column values of zero, then on the
'ready'event,add the real data and draw again. this will cause the chart to animate.
finally, since we have hard-coded the
ticksoption for our labels to appear.they will prevent the range filter from properly filtering the chart.
so we have to listen for the
'statechange'event, and reset the ticks that should be shown from the newly filtered data.see following working snippet...