官方教程
http://echarts.baidu.com/tutorial.html#5%20%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B%20ECharts
引入 ECharts
ECharts 3 开始不再强制使用 AMD 的方式按需引入,代码里也不再内置 AMD 加载器。因此引入方式简单了很多,只需要像普通的 JavaScript 库一样用 script 标签引入。
echarts.min.js 一般只需要这个文件就足够了
可以在官网下载 http://echarts.baidu.com/download.html
也可以在githut上下载 https://github.com/ecomfe/echarts/tree/master/dist 这里包含了几乎全部的文件
词云库的js文件可以在githut上下载 https://github.com/ecomfe/echarts-wordcloud
绘制一个简单的图表
在绘图前我们需要为 ECharts 准备一个具备高宽的 DOM 容器。
然后就可以通过 echarts.init 方法初始化一个 echarts 实例并通过 setOption 方法生成一个简单的柱状图,下面是完整代码。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ECharts</title> <!-- 引入 echarts.js --> <script src="echarts.min.js"></script> </head> <body> <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style=" 600px;height:400px;"></div> <script type="text/javascript"> // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 指定图表的配置项和数据 var option = { title: { text: 'ECharts 入门示例' }, tooltip: {}, legend: { data:['销量'] }, xAxis: { data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"] }, yAxis: {}, series: [{ name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); </script> </body> </html>
自己的示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ECharts</title> <script src="echarts.min.js"></script> <script src="echarts-wordcloud.min.js"></script> </head> <body> <div id="main" style="100%;height:400px;"></div> <script type="text/javascript"> var myChart = echarts.init(document.getElementById('main')); var option = { title:{ text:"中国", link:'https://github.com/ecomfe/echarts-wordcloud', sublink:'除去美国,中国', }, tooltip: {}, series: [{ type: 'wordCloud', gridSize: 20, sizeRange: [12, 50], rotationRange: [0, 0], shape: 'circle', textStyle: { normal: { color: function() { return 'rgb(' + [ Math.round(Math.random() * 160), Math.round(Math.random() * 160), Math.round(Math.random() * 160) ].join(',') + ')'; } }, emphasis: { shadowBlur: 10, shadowColor: '#333' } }, data: [{ name: '', value: 500, textStyle: { normal: { color: 'black' }, emphasis: { color: 'red' } } },{"name": "apoptosis", "value": 261},{"name": "neural regeneration", "value": 260},{"name": "oxidative stress", "value": 139},{"name": "nerve regeneration", "value": 127},{"name": "neuroprotection", "value": 124},{"name": "autophagy", "value": 118},{"name": "hippocampus", "value": 112},{"name": "inflammation", "value": 96},{"name": "microglia", "value": 94},{"name": "aging", "value": 87},{"name": "neuroregeneration", "value": 82},{"name": "meta-analysis", "value": 79},{"name": "neurodegeneration", "value": 75},{"name": "polymorphism", "value": 69},{"name": "mild cognitive impairment", "value": 59},{"name": "grants-supported paper", "value": 57},{"name": "neuroinflammation", "value": 54},{"name": "cognitive impairment", "value": 53},{"name": "mitochondria", "value": 51},{"name": "microrna", "value": 51},{"name": "brain injury", "value": 50},{"name": "functional connectivity", "value": 50},{"name": "stroke", "value": 50},{"name": "cognition", "value": 49},{"name": "depression", "value": 48},{"name": "dementia", "value": 46},{"name": "parkinson's disease", "value": 136},{"name": "reactive oxygen species", "value": 43},{"name": "biomarker", "value": 42},{"name": "nsfc grant", "value": 40},{"name": "learning and memory", "value": 39},{"name": "neurogenesis", "value": 38},{"name": "neurodegenerative diseases", "value": 37},{"name": "traditional chinese medicine", "value": 36},{"name": "brain-derived neurotrophic factor", "value": 36},{"name": "astrocytes", "value": 34},{"name": "cerebral ischemia", "value": 34},{"name": "memory", "value": 34},{"name": "fmri", "value": 33},{"name": "nf-u03bab", "value": 33},{"name": "neurons", "value": 32},{"name": "diffusion tensor imaging", "value": 31},{"name": "diabetes", "value": 31},{"name": "functional magnetic resonance imaging", "value": 31},{"name": "cognitive function", "value": 30},{"name": "magnetic resonance imaging", "value": 30} ] }] }; myChart.setOption(option); </script> </body> </html>
问题:开始找错了echarts,
http://echarts.baidu.com/echarts2/doc/start.html 这是echarts2
目前的版本是echarts3
--------
后面还有关于异步的教程,ajax