Anychart(二)获取数据源及简单示例
本文根据文档整理总结:http://www.anychart.com/products/anychart/docs/users-guide/index.html(Anychart目前版本6.2.0)
既然我们可以读取xml了,那么xml中的数据源怎么设置呢?下面我们来了解:
数据源定义在data节点中,一个xml可以有多个serise节点:
<?xml version="1.0" encoding="UTF-8"?> <anychart> <charts> <chart plot_type="CategorizedVertical"> <data> <!--数据源定义在series节点中,可以多个--> <series name="Sales" type="Bar"> <point name="John" y="10000" /> <point name="Jake" y="12000" /> <point name="Peter" y="18000" /> <point name="James" y="11000" /> <point name="Mary" y="9000" /> </series> </data> <chart_settings> <title enabled="false" /> <axes> <y_axis> <title> <text>Sales</text> </title> </y_axis> <x_axis> <title> <text>Manager</text> </title> </x_axis> </axes> </chart_settings> </chart> </charts> </anychart>
以上是一个最简单示例,
配合此图已经非常明显,不再多说了。当然上述是最简单例子,下面我们来看下CSV数据:
<?xml version="1.0" encoding="UTF-8"?> <anychart> <charts> <chart plot_type="CategorizedVertical"> <data> <series name="Series 1" type="Spline" data_source="CSV"> <csv_data_mapping data_set="simpleDataSet"> <field column="0" name="name" /> <field column="1" name="y" /> </csv_data_mapping> </series> <series name="Series 2" type="Bar" data_source="CSV"> <csv_data_mapping data_set="simpleDataSet"> <field column="0" name="name" /> <field column="2" name="y" /> </csv_data_mapping> </series> <series name="Series 3" type="SplineArea" data_source="CSV"> <csv_data_mapping data_set="simpleDataSet"> <field column="0" name="name" /> <field column="3" name="y" /> </csv_data_mapping> </series> </data> </chart> </charts> <data_sets> <csv_data_set name="simpleDataSet"> P1,174,5854,3242 P2,197,4171,3171 P3,155,1375,700 P4,15,1875,1287 P5,66,2246,1856 P6,85,2696,1126 P7,37,1287,987 P8,10,2140,1610 P9,44,1603,903 </csv_data_set> </data_sets> </anychart>