ChartSQL是一款可以让你利用SQL语句来生成网页图表的应用工具,ChartSQL的图表结果支持SVG的渲染方式,所以,我们只需在WEB端执行SQL即可在浏览器上轻松地显示相关数据图表。

ChartSQL的特点

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等。

  哈尔滨品用软件有限公司致力于为哈尔滨的中小企业制作大气、美观的优秀网站,并且能够搭建符合百度排名规范的网站基底,使您的网站无需额外费用,即可稳步提升排名至首页。欢迎体验最佳的哈尔滨网站建设