200 likes | 328 Views
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
E N D
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 Mappings Visualization Object User-generated SQL queries Data-to-Visualization Mapping Algorithms Data Source SQL Visualization Object SQL Query results SQL Data Source SQL Visualization Object
Google Charts • Images generated via parameterized URL strings (REST queries) • Google Charts Developer’s Guide: http://code.google.com/apis/chart/image/docs/making_charts.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 http://chart.apis.google.com/chart ?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,DDDDDD,AAAAAA,555555 Type = 3D Pie Data Labels Size Title Colors (per slice) Resulting Image
SQL Aggregate Queries • SQL Aggregate queries provide summary results (sums, averages, counts) with grouping • SELECT <grouping field>, <aggregate function> FROM <table or join> GROUP BY<grouping field> • 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 0-100. 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) http://chart.apis.google.com/chart?cht=bhs &chd=t:100,64.1148325358852,46.4114832535885,16.7464114832536,13.8755980861244 &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 Mapped to Google Chart URL String
Result Set (from AdventureWorks database) Aggregate data are normalized, then become the data values in the GoogleCharts URL. http://chart.apis.google.com/chart?cht=bhs &chd=t:100,64.1148325358852,46.4114832535885,16.7464114832536,13.8755980861244 &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 Mapped to Google Chart URL String
Result Set (from AdventureWorks database) Grouping field results become the label values in the GoogleCharts URL. http://chart.apis.google.com/chart?cht=bhs &chd=t:100,64.1148325358852,46.4114832535885,16.7464114832536,13.8755980861244 &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 Mapped to Google Chart URL String
URL String Returns Image http://chart.apis.google.com/chart?cht=bhs &chd=t:100,64.1148325358852,46.4114832535885,16.7464114832536,13.8755980861244 &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) 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) http://chart.apis.google.com/chart?cht=t&chtm=usa&chd=t:100,51.4060742407199,24.1394825646794,0.134983127109111,0.0899887514060742,0.0899887514060742 &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 Mapped to Google Chart URL String
URL String Returns Image http://chart.apis.google.com/chart?cht=t&chtm=usa&chd=t:100,51.4060742407199,24.1394825646794,0.134983127109111,0.0899887514060742,0.0899887514060742&chld=CAWAORILOHTX&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 Original query (aggregate) Production.ProductSubcategory.Name Drill-down field 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 Modified query (sub-aggregate)