// vue文件中引入echarts工具 let echarts = require('echarts/lib/echarts') require('echarts/lib/chart/line') // 如下的組件按需引入 require('echarts/lib/component/tooltip') // tooltip組件 require('echarts/lib/component/title') // title組件 require('echarts/lib/component/legend') // legend組件
// option將要設置如下字段感受就足夠使用了 option: { legend: {}, xAxis: {}, yAxis: {}, label: {}, tooltip: {}, series: [] }
legend: { data: ['招商銀行', '浦發銀行', '廣發銀行', '上海銀行'] },
xAxis: {
type: 'category', // 還有其餘的type,能夠去官網喵兩眼哦 data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], // x軸數據 name: '日期', // x軸名稱 // x軸名稱樣式 nameTextStyle: { fontWeight: 600, fontSize: 18 } },
yAxis: { type: 'value', name: '縱軸名稱', // y軸名稱 // y軸名稱樣式 nameTextStyle: { fontWeight: 600, fontSize: 18 } }
tooltip: { trigger: 'axis' // axis item none三個值 },
series: [
{
name: '招商銀行', data: [820, 932, 901, 934, 1290, 1330, 1320], type: 'line' }, { name: '浦發銀行', data: [620, 711, 823, 934, 1445, 1456, 1178], type: 'line' }, { name: '廣發銀行', data: [612, 920, 1140, 1160, 1190, 1234, 1321], type: 'line' }, { name: '上海銀行', data: [234, 320, 453, 567, 789, 999, 1200], type: 'line' } ]
// 折線圖顯示在這個div中, <div id="myChart"></div>
let myChart = echarts.init(document.getElementById('myChart')) myChart.setOption(this.option)
做者:一個寫前端的姑娘
連接:https://www.jianshu.com/p/cc7d08142e8b
javascript