new echarts.graphic.LinearGradient怎么引入
时间: 2024-06-13 17:04:09 浏览: 251
echarts文件中有dist\echarts.js,引入到自己的echrts中即可使用
在Vue中使用ECharts时,需要先安装ECharts并在组件中引入。在引入ECharts后,可以通过this.$echarts来访问ECharts的API。要使用new echarts.graphic.LinearGradient,需要在组件中先引入graphic模块。可以在组件中这样写:
```
import echarts from 'echarts/lib/echarts'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/title'
import 'echarts/lib/component/legend'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/bar'
import 'echarts/lib/chart/pie'
import 'echarts/lib/chart/scatter'
import 'echarts/lib/chart/radar'
import 'echarts/lib/chart/map'
import 'echarts/lib/chart/treemap'
import 'echarts/lib/chart/graph'
import 'echarts/lib/chart/gauge'
import 'echarts/lib/chart/funnel'
import 'echarts/lib/chart/parallel'
import 'echarts/lib/chart/sankey'
import 'echarts/lib/chart/boxplot'
import 'echarts/lib/chart/candlestick'
import 'echarts/lib/chart/effectScatter'
import 'echarts/lib/chart/lines'
import 'echarts/lib/chart/heatmap'
import 'echarts/lib/chart/pictorialBar'
import 'echarts/lib/chart/themeRiver'
import 'echarts/lib/chart/sunburst'
import 'echarts/lib/chart/custom'
import 'echarts/lib/component/graphic'
export default {
data() {
return {
chartData: {}
}
},
mounted() {
this.initChart()
},
methods: {
initChart() {
const chartDom = this.$refs.chart
const myChart = echarts.init(chartDom)
// 在这里使用new echarts.graphic.LinearGradient
const gradient = new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: '#00aaff'
}, {
offset: 0.7,
color: '#998866'
}, {
offset: 1,
color: '#998866'
}])
// 在这里使用gradient
myChart.setOption({
backgroundColor: gradient,
...
})
this.chartData = myChart
}
}
}
```
这样就可以在Vue组件中使用new echarts.graphic.LinearGradient了。
阅读全文