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] <about:invalid#zClosurez> -- 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/723b6ea3-7448-422d-bd0a-ccd76abe651c%40googlegroups.com.
<script 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 drawVisualization() { var data = google.visualization.arrayToDataTable([ ['Date', 'In Range', 'Average','Monitoring', '1', '2','3','4'], ['01/11/2018', 100, 89.73, 150, 70.51, 30.52, 48.14, 48.6], ['02/11/2018', 100, 86.72, 150, 69.28, 30.53, 48.1, 48.32], ['03/11/2018', 100, 86.72, 150, 69.28, 30.53, 48.1, 48.32], ['04/11/2018', 100, 86.72, 150, 69.28, 30.53, 48.1, 48.32], ['05/11/2018', 100, 86.47, 150, 69.28, 30.29, 48.1, 48.38], ['06/11/2018', 100, 86.73, 150, 70.76, 30.22, 48.06, 48.46], ['07/11/2018', 100, 84.48, 150, 71.25, 30.29, 48.08, 48.66], ['08/11/2018', 100, 85.97, 150, 71.75, 30.15, 48.07, 48.77], ['09/11/2018', 100, 87.97, 150, 75.72, 30.28, 48.35, 47.44], ['10/11/2018', 100, 87.97, 150, 75.72, 30.28, 48.35, 47.44], ['11/11/2018', 100, 87.97, 150, 75.72, 30.28, 48.35, 47.44], ['12/11/2018', 100, 90.72, 150, 78.21, 29.98, 48.44, 45.69], ['13/11/2018', 100, 88.62, 150, 78.71, 30.18, 48.53, 45.02], ['14/11/2018', 100, 91.52, 150, 79.83, 30.55, 48.58, 45.43], ['15/11/2018', 100, 96.67, 150, 87.79, 30.72, 48.6, 44.78], ['16/11/2018', 100, 99.87, 150, 88.78, 30.35, 48.69, 45.52], ['17/11/2018', 100, 99.87, 150, 88.78, 30.35, 48.69, 45.52], ['18/11/2018', 100, 99.87, 150, 88.78, 30.35, 48.69, 45.52], ['19/11/2018', 102.97, 102.97, 152.97, 92.08, 30.49, 48.73, 45.54], ['20/11/2018', 105.97, 105.97, 155.97, 93.53, 30.69, 48.7, 43.88], ['21/11/2018', 102.97, 102.97, 152.97, 92.53, 30.76, 48.7, 44.91], ['22/11/2018', 104.07, 104.07, 154.07, 92.53, 30.75, 48.71, 45.79], ['23/11/2018', 104.45, 104.45, 154.45, 90.04, 30.81, 48.7, 45.07], ['24/11/2018', 104.45, 104.45, 154.45, 90.04, 30.81, 48.7, 45.07], ['25/11/2018', 104.45, 104.45, 154.45, 90.04, 30.81, 48.7, 45.07], ['26/11/2018', 100, 99.45, 150, 89.3, 30.71, 48.72, 44.54], ['27/11/2018', 102.7, 102.7, 152.7, 92.28, 30.65, 48.69, 44.53], ['28/11/2018', 103.5, 103.5, 153.5, 91.28, 30.91, 48.68, 44.82], ['29/11/2018', 103, 103, 153, 91.28, 31.69, 48.81, 43.32], ['30/11/2018', 104.24, 104.24, 154.24, 90.78, 31.69, 48.81, 43.32], ['01/12/2018', 104.24, 104.24, 154.24, 90.78, 31.69, 48.81, 43.32], ['02/12/2018', 104.24, 104.24, 154.24, 90.78, 31.69, 48.81, 43.32], ['03/12/2018', 104.24, 104.24, 154.24, 91.28, 31.91, 48.85, 42.62], ['04/12/2018', 102.7, 102.7, 152.7, 92.28, 31.58, 48.8, 42.46], ['05/12/2018', 105.79, 105.79, 155.79, 95.01, 31.44, 48.8, 42.54], ['06/12/2018', 112.49, 112.49, 162.49, 97.48, 31.43, 48.8, 42.46], ['07/12/2018', 108.34, 108.34, 158.34, 95.52, 31.3, 48.8, 43.11], ['08/12/2018', 108.34, 108.34, 158.34, 95.52, 31.3, 48.8, 43.11], ['09/12/2018', 108.34, 108.34, 158.34, 95.52, 31.3, 48.8, 43.11], ['10/12/2018', 111.75, 111.75, 161.75, 98.49, 31.09, 48.85, 43.13], ['11/12/2018', 108.34, 108.34, 158.34, 95.52, 31.35, 48.79, 44.08], ['12/12/2018', 108.94, 108.94, 158.94, 94.78, 31.31, 48.83, 43.05], ['13/12/2018', 101.04, 101.04, 151.04, 91.04, 31.32, 48.8, 43.08], ['14/12/2018', 103.04, 103.04, 153.04, 91.77, 31.33, 48.8, 42.81], ['15/12/2018', 103.04, 103.04, 153.04, 91.77, 31.33, 48.8, 42.81], ['16/12/2018', 103.04, 103.04, 153.04, 91.77, 31.33, 48.8, 42.81], ['17/12/2018', 103.95, 103.95, 153.95, 92.04, 31.13, 48.8, 42.55], ['18/12/2018', 104.54, 104.54, 154.54, 93.28, 31.04, 34.04, 42.88], ['19/12/2018', 102.64, 102.64, 152.64, 93.28, 30.87, 35.03, 43.37], ['20/12/2018', 107.74, 107.74, 157.74, 93.28, 30.7, 35.01, 43.32], ['21/12/2018', 111.04, 111.04, 161.04, 92.77, 30.7, 35.01, 43.32], ['22/12/2018', 111.04, 111.04, 161.04, 92.77, 30.7, 35.01, 43.32], ['23/12/2018', 111.04, 111.04, 161.04, 92.77, 30.7, 35.01, 43.32], ['24/12/2018', 114.04, 114.04, 164.04, 92.77, 30.67, 31.12, 40.12], ['25/12/2018', 114.04, 114.04, 164.04, 92.77, 30.18, 31.14, 40.52], ['26/12/2018', 114.04, 114.04, 164.04, 93.27, 30.08, 31.32, 41.14], ['27/12/2018', 116.04, 116.04, 166.04, 93.78, 29.2, 31.49, 41.45], ['28/12/2018', 112.04, 112.04, 162.04, 93.28, 29.32, 31.35, 41.91], ['29/12/2018', 112.04, 112.04, 162.04, 93.28, 29.32, 31.35, 41.91], ['30/12/2018', 112.04, 112.04, 162.04, 93.28, 29.32, 31.35, 41.91], ]); 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 = 4; i < data.getNumberOfColumns(); i++) { columnsTable.addRow([i, data.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: data, 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(); }
