node後臺生成echarts圖表

 

 

 1 //2,生成圖片數據
 2     var option = {
 3       tooltip: {
 4         trigger: 'item',
 5         formatter: "{a} <br/>{b} : {c} ({d}%)"
 6       },
 7 
 8       series: [{
 9         name: '訪問來源',
10         type: 'pie',
11         radius: '55%',
12         center: ['50%', '60%'],
13         data: [
14           { value: 335, name: '直接訪問' },
15           { value: 310, name: '郵件營銷' },
16           { value: 234, name: '聯盟廣告' },
17           { value: 135, name: '視頻廣告' },
18           { value: 1548, name: '搜索引擎' }
19         ],
20         itemStyle: {
21           emphasis: {
22             shadowBlur: 10,
23             shadowOffsetX: 0,
24             shadowColor: 'rgba(0, 0, 0, 0.5)'
25           }
26         }
27       }]
28     };
29   //模塊引入
30     var node_echarts = require('node-echarts');
31     var path = require('path');
32 
33     node_echarts({
34       width: 500, // Image width, type is number. 
35       height: 500, // Image height, type is number. 
36       option: option, // Echarts configuration, type is Object.
37       //If the path  is not set, return the Buffer of image. 
38       path: path.join(__dirname, '../data/image1.png'), // Path is filepath of the image which will be created.
39       enableAutoDispose: true //Enable auto-dispose echarts after the image is created.
40     })
相關文章
相關標籤/搜索