方法一:
data為數組類型的,data:[10,20,30];
HTML
<div class="d_main" id="main3"></div>
css
.d_main{ width:80%; height:400px; margin:0 auto; }
js
1 var myChart3 = echarts.init(document.getElementById('main3'));// 每月標的總額 2 var option3 = { 3 backgroundColor:"#192138", //背景顏色 4 textStyle: { 5 color: '#02F5F6' //全局字體顏色,不設置則每個扇形的字和扇形顏色一致 6 }, 7 tooltip : { 8 trigger: 'axis', 9 axisPointer : { 10 type : 'shadow' 11 } 12 }, 13 grid: { 14 left: '3%', //表顯示的位置 15 right: '14%', 16 bottom: '3%', 17 containLabel: true, 18 backgroundColor:"rgba(256,256,256,0.5)" 19 }, 20 xAxis : [ 21 { 22 name:"單位(月)", //x軸單位 23 type : 'category', 24 boundaryGap : false, 25 data : ['','4月','5月','6月','7月','8月'] 26 } 27 ], 28 yAxis : [ 29 { 30 name:"單位(萬元)",//y軸單位 31 type : 'value' 32 } 33 ], 34 series : [ 35 { 36 name:'標的總額', 37 type:'line', 38 stack: '總量', 39 label: { 40 normal: { 41 show: true, 42 position: 'top' 43 } 44 }, 45 areaStyle: { 46 normal: { 47 color:"#01FFFF", //區域填充顏色 48 opacity:0.3 49 } 50 }, 51 itemStyle:{ 52 normal: { 53 color:"#01FFFF" //拐點顏色 54 } 55 }, 56 data:[], 57 lineStyle:{ 58 normal:{ 59 color:"#01FFFF", //線條顏色 60 opacity:0.5 61 } 62 } 63 } 64 ] 65 }; 66 67 68 $.get('data.json').done(function (data) { 69 // 填入數據 70 myChart3.setOption({ 71 series: [{ 72 // 根據名字對應到相應的系列 73 data: data 74 }] 75 }); 76 });
圖標展示

方法二:
data為對象類型,
data:[
{
value:134,
name:'7天標的',
itemStyle: {
normal: {
color: '#01FFFF'
}
}
}
]
HTML
<div class="d_main" id="main1"></div>
js
1 var myChart1 = echarts.init(document.getElementById('main1')); 2 var option1 = { 3 backgroundColor:"#192138", 4 color: ['#3398DB'], 5 textStyle: { 6 color: '#FFF' //全局字體顏色,不設置則每個扇形的字和扇形顏色一致 7 }, 8 tooltip : { 9 trigger: 'axis', 10 axisPointer : { // 坐標軸指示器,坐標軸觸發有效 11 type : 'shadow' // 默認為直線,可選為:'line' | 'shadow' 12 } 13 }, 14 grid: { 15 left: '3%', 16 right: '14%', 17 bottom: '3%', 18 containLabel: true 19 }, 20 xAxis : [ 21 { 22 name:"天數(天)", 23 type : 'category', 24 data : ['7天', '30天', '45天'], 25 axisTick: { 26 alignWithLabel: true 27 } 28 } 29 ], 30 yAxis : [ 31 { 32 name:"人數(人)", 33 type : 'value' 34 } 35 ], 36 series : [ 37 { 38 // name:'直接訪問', 39 type:'bar', 40 barWidth: '60%', 41 data:[] 42 } 43 ] 44 }; 45 46 // 使用剛指定的配置項和數據顯示圖表。 47 myChart1.setOption(option1); 48 $.get('data.json').done(function (data) { 49 // 填入數據 50 var myData=[]; 51 var myTemp; 52 var colorList1=['#01FFFF','#FFCA00','#C0FF00']; 53 for(var i=0;i<data.length;i++){ 54 myTemp={value:data[i],itemStyle:{normal:{color:colorList1[i]}}}; 55 myData.push(myTemp); 56 } 57 // console.log(myData); 58 myChart1.setOption({ 59 series: [{ 60 data:myData 61 }] 62 }); 63 });
圖標展示

