7b7c8390a658ba7d5d6be0779581f2f2510e9340.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <!DOCTYPE html>
  2. <html lang="zh-cn">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="description" content="ECharts">
  8. <meta name="author" content="kener.linfeng@gmail.com">
  9. <title>ECharts · Start</title>
  10. <link rel="shortcut icon" href="./asset/ico/favicon.png">
  11. <link href="./asset/css/font-awesome.min.css" rel="stylesheet">
  12. <link href="./asset/css/bootstrap.css" rel="stylesheet">
  13. <link href="./asset/css/carousel.css" rel="stylesheet">
  14. <link href="./asset/css/echartsHome.css" rel="stylesheet">
  15. <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  16. <!--[if lt IE 9]>
  17. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  18. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  19. <![endif]-->
  20. <script src="./asset/js/google-code-prettify.js"></script>
  21. <link href="./asset/css/google-code-prettify.css" rel="stylesheet" />
  22. <link href="./asset/css/monokai.css" rel="stylesheet">
  23. <style type="text/css">
  24. .nav-tabs.nav-justified > .active > a, .nav-tabs.nav-justified > .active > a:hover {
  25. background-color:rgb(247, 247, 247);
  26. font-weight: bolder;
  27. }
  28. .tab-content {
  29. padding:20px;
  30. border-left: 1px solid #dddddd;
  31. border-right: 1px solid #dddddd;
  32. border-top: 0px;
  33. }
  34. </style>
  35. </head>
  36. <body onload="prettyPrint()">
  37. <!-- Fixed navbar -->
  38. <div class="navbar navbar-default navbar-fixed-top" role="navigation" id="head"></div>
  39. <div class="container">
  40. <h2 class="text-center">5分钟上手写ECharts的第一个图表</h2>
  41. <ul class="nav nav-tabs nav-justified">
  42. <li class="active">
  43. <a id = "o-aqi" href="#main0" data-toggle="tab">模块化单文件引入(推荐)</a></li>
  44. <li><a id = "o-pm25" href="#main1" data-toggle="tab">标签式单文件引入</a></li>
  45. </ul>
  46. <div class="tab-content">
  47. <div class="tab-pane active" id="main0">
  48. <b class="title">1、新建一个echarts.html文件,为ECharts准备一个具备大小(宽高)的Dom。</b>
  49. <pre class="prettyprint"><xmp><!DOCTYPE html>
  50. <head>
  51. <meta charset="utf-8">
  52. <title>ECharts</title>
  53. </head>
  54. <body>
  55. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  56. <div id="main" style="height:400px"></div>
  57. </body></xmp></pre>
  58. <b class="title">2、新建&lt;script&gt;标签引入模块化单文件echarts.js</b>
  59. <pre class="prettyprint"><xmp><!DOCTYPE html>
  60. <head>
  61. <meta charset="utf-8">
  62. <title>ECharts</title>
  63. </head>
  64. <body>
  65. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  66. <div id="main" style="height:400px"></div>
  67. <!-- ECharts单文件引入 -->
  68. <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
  69. </body></xmp></pre>
  70. <b class="title">3、新建&lt;script&gt;标签中为模块加载器配置echarts和所需图表的路径(相对路径为从当前页面链接到echarts.js),引入图表文件见<a href="doc.html#引入ECharts2" target="_blank">引入ECharts2</a></b>
  71. <pre class="prettyprint"><xmp><!DOCTYPE html>
  72. <head>
  73. <meta charset="utf-8">
  74. <title>ECharts</title>
  75. </head>
  76. <body>
  77. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  78. <div id="main" style="height:400px"></div>
  79. <!-- ECharts单文件引入 -->
  80. <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
  81. <script type="text/javascript">
  82. // 路径配置
  83. require.config({
  84. paths: {
  85. echarts: 'http://echarts.baidu.com/build/dist'
  86. }
  87. });
  88. </script>
  89. </body></xmp></pre>
  90. <b class="title">4、&lt;script&gt;标签内动态加载echarts和所需图表,回调函数中可以初始化图表并驱动图表的生成,option见<a href="doc.html#Option" target="_blank">API & Doc</a></b>
  91. <pre class="prettyprint"><xmp><!DOCTYPE html>
  92. <head>
  93. <meta charset="utf-8">
  94. <title>ECharts</title>
  95. </head>
  96. <body>
  97. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  98. <div id="main" style="height:400px"></div>
  99. <!-- ECharts单文件引入 -->
  100. <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
  101. <script type="text/javascript">
  102. // 路径配置
  103. require.config({
  104. paths: {
  105. echarts: 'http://echarts.baidu.com/build/dist'
  106. }
  107. });
  108. // 使用
  109. require(
  110. [
  111. 'echarts',
  112. 'echarts/chart/bar' // 使用柱状图就加载bar模块,按需加载
  113. ],
  114. function (ec) {
  115. // 基于准备好的dom,初始化echarts图表
  116. var myChart = ec.init(document.getElementById('main'));
  117. var option = {
  118. tooltip: {
  119. show: true
  120. },
  121. legend: {
  122. data:['销量']
  123. },
  124. xAxis : [
  125. {
  126. type : 'category',
  127. data : ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
  128. }
  129. ],
  130. yAxis : [
  131. {
  132. type : 'value'
  133. }
  134. ],
  135. series : [
  136. {
  137. "name":"销量",
  138. "type":"bar",
  139. "data":[5, 20, 40, 10, 10, 20]
  140. }
  141. ]
  142. };
  143. // 为echarts对象加载数据
  144. myChart.setOption(option);
  145. }
  146. );
  147. </script>
  148. </body></xmp></pre>
  149. <b>5、浏览器中打开echarts.html,就可看到以下效果</b>
  150. </div>
  151. <!------------------------------>
  152. <div class="tab-pane" id="main1">
  153. <b class="title">1、新建一个echarts.html文件。为ECharts准备一个具备大小(宽高)的Dom。</b>
  154. <pre class="prettyprint"><xmp><!DOCTYPE html>
  155. <head>
  156. <meta charset="utf-8">
  157. <title>ECharts</title>
  158. </head>
  159. <body>
  160. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  161. <div id="main" style="height:400px"></div>
  162. </body></xmp></pre>
  163. <b class="title">2、新建&lt;script&gt;标签引入echarts-all.js,引入图表文件见<a href="doc.html#引入ECharts3" target="_blank">引入ECharts3</a></b>
  164. <pre class="prettyprint"><xmp><!DOCTYPE html>
  165. <head>
  166. <meta charset="utf-8">
  167. <title>ECharts</title>
  168. </head>
  169. <body>
  170. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  171. <div id="main" style="height:400px"></div>
  172. <!-- ECharts单文件引入 -->
  173. <script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>
  174. </body></xmp></pre>
  175. <b class="title">3、新建&lt;script&gt;标签,使用全局变量echarts初始化图表并驱动图表的生成,option见<a href="doc.html#Option" target="_blank">API & Doc</a></b>
  176. <pre class="prettyprint"><xmp><!DOCTYPE html>
  177. <head>
  178. <meta charset="utf-8">
  179. <title>ECharts</title>
  180. </head>
  181. <body>
  182. <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  183. <div id="main" style="height:400px"></div>
  184. <!-- ECharts单文件引入 -->
  185. <script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>
  186. <script type="text/javascript">
  187. // 基于准备好的dom,初始化echarts图表
  188. var myChart = echarts.init(document.getElementById('main'));
  189. var option = {
  190. tooltip: {
  191. show: true
  192. },
  193. legend: {
  194. data:['销量']
  195. },
  196. xAxis : [
  197. {
  198. type : 'category',
  199. data : ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
  200. }
  201. ],
  202. yAxis : [
  203. {
  204. type : 'value'
  205. }
  206. ],
  207. series : [
  208. {
  209. "name":"销量",
  210. "type":"bar",
  211. "data":[5, 20, 40, 10, 10, 20]
  212. }
  213. ]
  214. };
  215. // 为echarts对象加载数据
  216. myChart.setOption(option);
  217. </script>
  218. </body></xmp></pre>
  219. <b>4、浏览器中打开echarts.html,就可看到以下效果</b>
  220. </div>
  221. </div>
  222. <div id="main" style="height:400px;border: 1px solid #dddddd;border-top-width:0"></div>
  223. <div class="row" style="margin: 30px 0;">
  224. <h2>最好的参考资源:实例</h2>
  225. <p>ECharts可以说是数据驱动的图表,大部分时候你关心的是那个option该如何实现,官网的<a href="./doc.html">文档</a>提供详细的说明,另外我们还有近100个<a href="./example.html">实例</a>,这些例子都为你展现了最核心的option代码,可以通过在线修改查看效果,ECharts是玩出来的,希望你玩得开心。</p>
  226. </div>
  227. </div>
  228. <script src="../build/dist/echarts.js"></script>
  229. <script type="text/javascript">
  230. require.config({
  231. paths: {
  232. echarts: '../build/dist'
  233. }
  234. });
  235. require(
  236. [
  237. 'echarts',
  238. 'echarts/chart/bar'
  239. ],
  240. function (ec) {
  241. var myChart = ec.init(document.getElementById('main'));
  242. myChart.setOption(option);
  243. }
  244. );
  245. var option = {
  246. tooltip: {
  247. show: true
  248. },
  249. legend: {
  250. data:['销量']
  251. },
  252. xAxis : [
  253. {
  254. type : 'category',
  255. data : ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
  256. }
  257. ],
  258. yAxis : [
  259. {
  260. type : 'value'
  261. }
  262. ],
  263. series : [
  264. {
  265. "name":"销量",
  266. "type":"bar",
  267. "data":[5,20,40,10,10,20]
  268. }
  269. ]
  270. };
  271. </script>
  272. <footer id="footer"></footer>
  273. <!-- Le javascript
  274. ================================================== -->
  275. <!-- Placed at the end of the document so the pages load faster -->
  276. <script src="./asset/js/jquery.min.js"></script>
  277. <script type="text/javascript" src="./asset/js/echartsHome.js"></script>
  278. <script src="./asset/js/bootstrap.min.js"></script>
  279. </body>
  280. </html>