Dashboard Creation Mapping SQL queries to Google Chart Images
SQL – to – Visualization Mappings Idea: – Automatic mapping of SQL queries to visualization scripts – Enable easy creation of dashboards based on SQL queries – Enable drill-down and other interactive features – Provide a pedagogical tool for teaching practical data visualization techniques
Data-to-Visualization Mapping Algorithms Data Source Visualiza tion Object User-generated SQL queries SQL Query results Data –to- Visualization Mappings
Google Charts Images generated via parameterized URL strings (REST queries) Google Charts Developer’s Guide: s.html s.html Parameters include chart type, chart properties, data, legends, chart sizes and colors, etc. Google returns a PNG file with the graphic for the request
Example Google Charts REST String ?cht=p3 &chd=t:100,90,80,45,42.5,15 &chl=First|Second|Third|Fourth|Fifth|Sixth &chs=500x200 &chtt=My Chart &chco=FF0000,00FF00,0000FF,000000,FFFFFF,FF00FF,00FF00,00FFFF,DDDD DD,AAAAAA, Type = 3D Pie Data Labels Size Title Colors (per slice) Resulting Image
Types of Google Charts
SQL Aggregate Queries SQL Aggregate queries provide summary results (sums, averages, counts) with grouping SELECT, FROM GROUP BY Ideal for these visualizations: bar, line, and pie charts
Mapping Aggregate SQL Queries to Google Charts Aggregate query From query’s result set, generate the URL parameter values for: – chl (from grouping column) – chd (from aggregate column) – NOTE: for Google Charts, data range is So original data must be normalized before being sent. Other parameters are set based on user preferences
Sample Aggregate Query From AdventureWorks database: SELECT Production.ProductCategory.Name, COUNT(*) FROM Production.ProductCategory FULL OUTER JOIN Production.ProductSubcategory ON Production.ProductCategory.ProductCategoryID = Production.ProductSubcategory.ProductCategoryID FULL OUTER JOIN Production.Product ON Production.ProductSubcategory.ProductSubcategoryID = Production.Product.ProductSubcategoryID GROUP BY Production.ProductCategory.Name order by count(*) desc
Sample AggregateQuery From AdventureWorks database: SELECT Production.ProductCategory.Name, COUNT(*) FROM Production.ProductCategory FULL OUTER JOIN Production.ProductSubcategory ON Production.ProductCategory.ProductCategoryID = Production.ProductSubcategory.ProductCategoryID FULL OUTER JOIN Production.Product ON Production.ProductSubcategory.ProductSubcategoryID = Production.Product.ProductSubcategoryID GROUP BY Production.ProductCategory.Name order by count(*) desc Grouping column, aggregate column Grouping clause
Result Set (from AdventureWorks database) Mapped to Google Chart URL String &chd=t:100, , , , &chxt=x,y&chxl=0:|0|209|1:|Accessories|Clothing|Bikes|Components|NULL &chs=310x150 &chtt=Product Category Counts &chma=30,30,30,30&chco=FF0000,00FF00,0000FF,000000,FFFFFF,FF00FF,00
Result Set (from AdventureWorks database) Mapped to Google Chart URL String &chd=t:100, , , , &chxt=x,y&chxl=0:|0|209|1:|Accessories|Clothing|Bikes|Components|NULL &chs=310x150 &chtt=Product Category Counts &chma=30,30,30,30&chco=FF0000,00FF00,0000FF,000000,FFFFFF,FF00FF,00 Aggregate data are normalized, then become the data values in the GoogleCharts URL.
Result Set (from AdventureWorks database) Mapped to Google Chart URL String &chd=t:100, , , , &chxt=x,y&chxl=0:|0|209|1:|Accessories|Clothing|Bikes|Components|NULL &chs=310x150 &chtt=Product Category Counts &chma=30,30,30,30&chco=FF0000,00FF00,0000FF,000000,FFFFFF,FF00FF,00 Grouping field results become the label values in the GoogleCharts URL.
URL String Returns Image &chd=t:100, , , , &chxt=x,y&chxl=0:|0|209|1:|Accessories|Clothing|Bikes|Components|NULL &chs=310x150 &chtt=Product Category Counts
Visualizing Geographic Data The Google Charts API includes map charts in which you can adjust colors of a map’s regions using numeric data. Good for use on aggregate queries where the group attributes are geographic units (e.g. states of the US, countries of Europe, etc.)
Result Set (from AdventureWorks database) Mapped to Google Chart URL String Grouping field in result set (state abbrev) is associated with the states of the chart (cht=t indicates a map, chtm=usa indicates US map) , , , &chld=CAWAORILOHTX&chs=250x150&chtt=Tot Customers by State&chma=30,30,30,30&chco=FFFFFF,EEEEEE,0000FF,FF0000&chf=bg,s,EAF7FE C C
URL String Returns Image , , , &chld=CAWA ORILOHTX&chs=250x150&chtt=Tot Customers by State&chma=30,30,30,30&chco=FFFFFF,EEEEEE,0000FF,FF0000&chf=bg,s,EAF7FE
Drill-Down From aggregate, get sub-aggregates for each group For a given query, you can specify a sequence of drill-down fields, which are used for each subsequent drill-down request
Example Drill-Down SELECT Production.ProductCategory.Name, COUNT(*) FROM Production.ProductCategory FULL OUTER JOIN Production.ProductSubcategory ON Production.ProductCategory.ProductCategoryID = Production.ProductSubcategory.ProductCategoryID FULL OUTER JOIN Production.Product ON Production.ProductSubcategory.ProductSubcategoryID = Production.Product.ProductSubcategoryID GROUP BY Production.ProductCategory.Name order by count(*) desc SELECT Production.ProductSubcategory.Name, COUNT(*) FROM Production.ProductCategory FULL OUTER JOIN Production.ProductSubcategory ON Production.ProductCategory.ProductCategoryID = Production.ProductSubcategory.ProductCategoryID FULL OUTER JOIN Production.Product ON Production.ProductSubcategory.ProductSubcategoryID = Production.Product.ProductSubcategoryID WHERE Production.ProductCategory.Name = 'Accessories' GROUP BY Production.ProductSubcategory.Name ORDER BY count(*) desc Production.ProductSubcategory.Name Modified query (sub-aggregate) Original query (aggregate) Drill-down field
Example Drill-Down