ChartSQL的特點
- 直接輸入SQL語句即可生成相應的資料圖表,非常簡單。
- 可在瀏覽器端顯示SVG格式的圖表
- 支援多種圖表形式,線圖、柱形圖、餅圖都可以支援。
ChartSQL的使用方法
帶資料點的線形圖
SQL程式碼:
IMPORT TABLE city_temperatures FROM 'csv:examples/data/city_temperatures.csv?headers=true'; DRAW LINECHART WITH AXIS LEFT AXIS BOTTOM LEGEND TOP LEFT INSIDE; SELECT city AS series, month AS x, temperature AS y, "Avg. Temperatures in " + month + " in " + city + ": " + temperature as label, "circle" as pointstyle FROM city_temperatures;
執行程式碼:
$ fnordmetric-cli --format=svg examples/linECharts/lines_with_points.sql
效果圖:
簡單的區域圖
SQL程式碼:
IMPORT TABLE example_data FROM 'csv:examples/data/measurement.csv?headers=true'; DRAW AREACHART WITH AXIS BOTTOM AXIS LEFT GRID HORIZONTAL; SELECT 'data' AS series, FROM_TIMESTAMP(time) AS x, value2 * 1000 AS y, 'solid' as linestyle FROM example_data WHERE series = "measurement2";
執行程式碼:
$ fnordmetric-cli --format=svg examples/areacharts/simple_area.sql
效果圖:
柱形圖
SQL程式碼:
IMPORT TABLE gdp_per_capita FROM 'csv:examples/data/gdp_per_capita.csv?headers=true'; DRAW BARCHART WITH ORIENTATION VERTICAL AXIS BOTTOM GRID HORIZONTAL LEGEND TOP RIGHT INSIDE; SELECT year AS series, isocode AS x, gdp AS y FROM gdp_per_capita WHERE year = "2010" OR year = '2009' or year = '2008' ORDER BY gdp DESC LIMIT 9;
執行程式碼:
$ fnordmetric-cli --format=svg examples/barcharts/vertical_bars.sql
效果圖:
總結
總體來說ChartSQL的使用還算比較簡單,我們只需要執行相應的SQL就可以顯示資料圖表了,省去了自己編寫的圖表生成控制元件。當然,ChartSQL也並不適合所有的圖表應用,因為很多時候我們並不是把資料存入資料庫,比如XML、JSON等。
來自:碼農網
相關閱讀
評論(1)