Hi Daniel, Not sure how to post a public page but you are quite welcome to see the whole code in the attached.
Regards, Steve. On Tuesday, 24 December 2019 10:19:44 UTC, Steven Lovell wrote: > > Hi All, > > I'm new to Google charts and was wondering if anyone out there knows if it > is possible to have a combo chart with filters that do the following. > > The stacked values should always be present on the chart and the filter > will only act upon the line data values. > > So far I can hide the stacked values from the filter. When using the > filter it removes the stacked section, only leaving the filtered values on > the chart. I've attached my attempt if anyone would like to take a look. > > Any help would be greatly appreciated. > > Regards, > Steve. > [image: Chart.PNG] > -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/9a915257-1e68-4622-a355-0793821cc531%40googlegroups.com.
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div> <div id="colFilter_div"></div> //google.charts.load('current', {'packages':['corechart']}); // google.charts.setOnLoadCallback(drawVisualization); function drawChart() { var data1 = new google.visualization.DataTable(); data1.addColumn('string', 'Date'); data1.addColumn('number', 'In Range'); data1.addColumn('number', 'Average'); data1.addColumn('number', 'Monitoring'); data1.addRows([ ['03/12/2018', 104.24, 104.24, 154.24], ['04/12/2018', 102.7, 102.7, 152.7], ['05/12/2018', 105.79, 105.79, 155.79], ['06/12/2018', 112.49, 112.49, 162.49], ['07/12/2018', 108.34, 108.34, 158.34], ['08/12/2018', 108.34, 108.34, 158.34], ['09/12/2018', 108.34, 108.34, 158.34], ['10/12/2018', 111.75, 111.75, 161.75], ['11/12/2018', 108.34, 108.34, 158.34], ['12/12/2018', 108.94, 108.94, 158.94], ['13/12/2018', 101.04, 101.04, 151.04], ['14/12/2018', 103.04, 103.04, 153.04], ['15/12/2018', 103.04, 103.04, 153.04], ['16/12/2018', 103.04, 103.04, 153.04], ['17/12/2018', 103.95, 103.95, 153.95], ['18/12/2018', 104.54, 104.54, 154.54], ['19/12/2018', 102.64, 102.64, 152.64], ['20/12/2018', 107.74, 107.74, 157.74], ['21/12/2018', 111.04, 111.04, 161.04], ['22/12/2018', 111.04, 111.04, 161.04], ['23/12/2018', 111.04, 111.04, 161.04], ['24/12/2018', 114.04, 114.04, 164.04], ['25/12/2018', 114.04, 114.04, 164.04], ['26/12/2018', 114.04, 114.04, 164.04], ['27/12/2018', 116.04, 116.04, 166.04], ['28/12/2018', 112.04, 112.04, 162.04], ['29/12/2018', 112.04, 112.04, 162.04], ['30/12/2018', 112.04, 112.04, 162.04] ]); var data2 = new google.visualization.DataTable(); data2.addColumn('string', 'Date'); data2.addColumn('number', '1'); data2.addColumn('number', '2'); data2.addColumn('number', '3'); data2.addColumn('number', '4'); data2.addRows([ ['03/12/2018', 91.28, 31.91, 48.85, 42.62], ['04/12/2018', 92.28, 31.58, 48.8, 42.46], ['05/12/2018', 95.01, 31.44, 48.8, 42.54], ['06/12/2018', 97.48, 31.43, 48.8, 42.46], ['07/12/2018', 95.52, 31.3, 48.8, 43.11], ['08/12/2018', 95.52, 31.3, 48.8, 43.11], ['09/12/2018', 95.52, 31.3, 48.8, 43.11], ['10/12/2018', 98.49, 31.09, 48.85, 43.13], ['11/12/2018', 95.52, 31.35, 48.79, 44.08], ['12/12/2018', 94.78, 31.31, 48.83, 43.05], ['13/12/2018', 91.04, 31.32, 48.8, 43.08], ['14/12/2018', 91.77, 31.33, 48.8, 42.81], ['15/12/2018', 91.77, 31.33, 48.8, 42.81], ['16/12/2018', 91.77, 31.33, 48.8, 42.81], ['17/12/2018', 92.04, 31.13, 48.8, 42.55], ['18/12/2018', 93.28, 31.04, 34.04, 42.88], ['19/12/2018', 93.28, 30.87, 35.03, 43.37], ['20/12/2018', 93.28, 30.7, 35.01, 43.32], ['21/12/2018', 92.77, 30.7, 35.01, 43.32], ['22/12/2018', 92.77, 30.7, 35.01, 43.32], ['23/12/2018', 92.77, 30.7, 35.01, 43.32], ['24/12/2018', 92.77, 30.67, 31.12, 40.12], ['25/12/2018', 92.77, 30.18, 31.14, 40.52], ['26/12/2018', 93.27, 30.08, 31.32, 41.14], ['27/12/2018', 93.78, 29.2, 31.49, 41.45], ['28/12/2018', 93.28, 29.32, 31.35, 41.91], ['29/12/2018', 93.28, 29.32, 31.35, 41.91], ['30/12/2018', 93.28, 29.32, 31.35, 41.91] ]); var joinedData = google.visualization.data.join(data1, data2, 'full', [[0, 0]], [1,2,3], [1,2,3,4]); var columnsTable = new google.visualization.DataTable(); columnsTable.addColumn('number', 'colIndex'); columnsTable.addColumn('string', 'colLabel'); var initState= {selectedValues: []}; // put the columns into this data table (skip column 0,1,2,3) for (var i = 1; i < data2.getNumberOfColumns(); i++) { columnsTable.addRow([i, data2.getColumnLabel(i)]); } // you can set individual columns to be the default columns (instead of populating via the loop above) like this: // initState.selectedValues.push(data.getColumnLabel(4)); var chart = new google.visualization.ChartWrapper({ chartType: 'ComboChart', containerId: 'chart_div', dataTable: joinedData, options: { width: 800, height: 400, seriesType: 'area', series: { 3: {type: 'line'}, 4: {type: 'line'}, 5: {type: 'line'}, 6: {type: 'line'}}, colors: ['green', 'black','lightgrey','blue','red','yellow','orange'], // 'view': {'columns': [4, 7]} } }); var columnFilter = new google.visualization.ControlWrapper({ controlType: 'CategoryFilter', containerId: 'colFilter_div', dataTable: columnsTable, options: { filterColumnLabel: 'colLabel', filterColumnIndex: 1, useFormattedValue: true, ui: { label: 'Name', allowTyping: false, allowMultiple: true, caption : '1', allowNone: true, selectedValuesLayout: 'BelowStacked' } }, state: initState }); function setChartView () { var state = columnFilter.getState(); var row; var view = { columns: [0] }; for (var i = 0; i < state.selectedValues.length; i++) { row = columnsTable.getFilteredRows([{column: 1, value: state.selectedValues[i]}])[0]; view.columns.push(columnsTable.getValue(row, 0)); } // sort the indices into their original order view.columns.sort(function (a, b) { return (a - b); }); if (state.selectedValues.length > 0) { chart.setView(view); } else { chart.setView(null); } chart.draw(); } google.visualization.events.addListener(columnFilter, 'statechange', setChartView); setChartView(); columnFilter.draw(); } google.load('visualization', '1', {packages:['corechart'], callback: drawChart});
