This example demonstrates how you can use a dropdown menu to allow a user to select, or filter, the data displayed on a column chart.
Uses jQuery Selectors, the jQuery val function, and the jQuery change function.
The select
element will be used to filter the data for a column chart that will be inserted in the "chart2" div
.
Add the following code to the bottom of the setup()
function. This will "listen" for changes to the dropdown selector and re-run the composeCharts()
function when it is changed.
The following "viz.chart" function defines a column chart that will use the value selected by the user in the SQL to retrieve the right column of data to chart.
To create a grid layout like the sketch above, adjust your HTML and CSS like the following examples. But be careful not to simply copy and paste everything here.
Notice that the "card" for the first chart also has a class called "full-width". We will use this class to make a chart span the full width of the page, while the others will fall into a grid with 3 charts per row.
First, notice the id="page" (#page) style defines the normal grid design of 3 elements (or 3 columns) per row. grid-template-columns: 1fr 1fr 1fr;
This applies to all the grid elements inside the id = "page" element.
Next, any element with the class "full-width" will start at the first position and span 3 columns. grid-column: 1 / span 3;
We can also add a style (look for @media ... below ) that makes our dashboard mobile-friendly where all the charts just stack on top of each other if the screen is less than 700px wide.