欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue使用echarts實(shí)現(xiàn)立體柱形圖

 更新時(shí)間:2022年04月02日 14:38:25   作者:小游-523??于?2020-11-06?18:39:30?發(fā)布??1775  
這篇文章主要為大家詳細(xì)介紹了vue使用echarts實(shí)現(xiàn)立體柱形圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue使用echarts實(shí)現(xiàn)立體柱形圖的具體代碼,供大家參考,具體內(nèi)容如下

立體柱形圖是由前面、右面、上面三部分組成,繪制時(shí)需要先繪制前面為一個(gè)圖形,右面和上面繪制為一個(gè)圖形,然后在echats中注冊(cè),在option的series中renderItem中渲染
代碼如下:

(1)注冊(cè)繪制圖形

registry () {
? ? ? let MyCubeRect = this.$echarts.graphic.extendShape({
? ? ? ? shape: {
? ? ? ? ? x: 0,
? ? ? ? ? y: 0,
? ? ? ? ? width: 20,
? ? ? ? ? zWidth: 8,
? ? ? ? ? zHeight: 4
? ? ? ? },
? ? ? ? buildPath: function (ctx, shape) {
? ? ? ? ? const api = shape.api
? ? ? ? ? const xAxisPoint = api.coord([shape.xValue, 0])
? ? ? ? ? const p0 = [shape.x, shape.y]
? ? ? ? ? const p1 = [shape.x - shape.width / 2, shape.y]
? ? ? ? ? const p4 = [shape.x + shape.width / 2, shape.y]
? ? ? ? ? const p2 = [shape.x - shape.width / 2, xAxisPoint[1]]
? ? ? ? ? const p3 = [shape.x + shape.width / 2, xAxisPoint[1]]

? ? ? ? ? ctx.moveTo(p0[0], p0[1])
? ? ? ? ? ctx.lineTo(p1[0], p1[1])
? ? ? ? ? ctx.lineTo(p2[0], p2[1])
? ? ? ? ? ctx.lineTo(p3[0], p3[1])
? ? ? ? ? ctx.lineTo(p4[0], p4[1])
? ? ? ? ? ctx.lineTo(p0[0], p0[1])
? ? ? ? ? ctx.closePath()
? ? ? ? }
? ? ? })
? ? ? let MyCubeShadow = this.$echarts.graphic.extendShape({
? ? ? ? shape: {
? ? ? ? ? x: 0,
? ? ? ? ? y: 0,
? ? ? ? ? width: 20,
? ? ? ? ? zWidth: 8,
? ? ? ? ? zHeight: 4
? ? ? ? },
? ? ? ? buildPath: function (ctx, shape) {
? ? ? ? ? const api = shape.api
? ? ? ? ? const xAxisPoint = api.coord([shape.xValue, 0])
? ? ? ? ? const p1 = [shape.x - shape.width / 2, shape.y]
? ? ? ? ? const p4 = [shape.x + shape.width / 2, shape.y]
? ? ? ? ? const p6 = [shape.x + shape.width / 2 + shape.zWidth, shape.y - shape.zHeight]
? ? ? ? ? const p7 = [shape.x - shape.width / 2 + shape.zWidth, shape.y - shape.zHeight]
? ? ? ? ? const p3 = [shape.x + shape.width / 2, xAxisPoint[1]]
? ? ? ? ? const p5 = [shape.x + shape.width / 2 + shape.zWidth, xAxisPoint[1] - shape.zHeight]

? ? ? ? ? ctx.moveTo(p4[0], p4[1])
? ? ? ? ? ctx.lineTo(p3[0], p3[1])
? ? ? ? ? ctx.lineTo(p5[0], p5[1])
? ? ? ? ? ctx.lineTo(p6[0], p6[1])
? ? ? ? ? ctx.lineTo(p4[0], p4[1])

? ? ? ? ? ctx.moveTo(p4[0], p4[1])
? ? ? ? ? ctx.lineTo(p6[0], p6[1])
? ? ? ? ? ctx.lineTo(p7[0], p7[1])
? ? ? ? ? ctx.lineTo(p1[0], p1[1])
? ? ? ? ? ctx.lineTo(p4[0], p4[1])
? ? ? ? ? ctx.closePath()
? ? ? ? }
? ? ? })
? ? ? this.$echarts.graphic.registerShape('MyCubeRect', MyCubeRect)
? ? ? this.$echarts.graphic.registerShape('MyCubeShadow', MyCubeShadow)
? ? }

(2)渲染圖形

barChartOption: {
? ? ? ? tooltip: {
? ? ? ? ? trigger: 'axis',
? ? ? ? ? axisPointer: {
? ? ? ? ? ? type: 'cross',
? ? ? ? ? ? label: {
? ? ? ? ? ? ? backgroundColor: '#6a7985'
? ? ? ? ? ? }
? ? ? ? ? }
? ? ? ? },
? ? ? ? grid: {
? ? ? ? ? containLabel: true,
? ? ? ? ? top: '30px',
? ? ? ? ? bottom: '0px',
? ? ? ? ? left: '0px'
? ? ? ? },
? ? ? ? xAxis: {
? ? ? ? ? type: 'category',
? ? ? ? ? axisLabel: {
? ? ? ? ? ? interval: 0,
? ? ? ? ? ? fontSize: fontSize(12)
? ? ? ? ? },
? ? ? ? ? axisLine: {
? ? ? ? ? ? show: false,
? ? ? ? ? ? lineStyle: {
? ? ? ? ? ? ? color: '#98b9c5'
? ? ? ? ? ? }
? ? ? ? ? },
? ? ? ? ? data: [] ?//通過(guò)后端傳入數(shù)據(jù)js傳入
? ? ? ? },
? ? ? ? yAxis: {
? ? ? ? ? type: 'value',
? ? ? ? ? axisLabel: {
? ? ? ? ? ? fontSize: fontSize(12)
? ? ? ? ? },
? ? ? ? ? axisLine: {
? ? ? ? ? ? show: false,
? ? ? ? ? ? lineStyle: {
? ? ? ? ? ? ? color: '#98b9c5'
? ? ? ? ? ? }
? ? ? ? ? },
? ? ? ? ? splitLine: {
? ? ? ? ? ? lineStyle: {
? ? ? ? ? ? ? color: '#3a586a',
? ? ? ? ? ? ? type: 'dashed'
? ? ? ? ? ? }
? ? ? ? ? }
? ? ? ? },
? ? ? ? series: [{
? ? ? ? ? name: '單位面積能耗',
? ? ? ? ? type: 'custom',
? ? ? ? ? renderItem: (params, api) => {
? ? ? ? ? ? let location = api.coord([api.value(0), api.value(1)])
? ? ? ? ? ? return {
? ? ? ? ? ? ? type: 'group',
? ? ? ? ? ? ? children: [{
? ? ? ? ? ? ? ? type: 'MyCubeRect',
? ? ? ? ? ? ? ? shape: {
? ? ? ? ? ? ? ? ? api,
? ? ? ? ? ? ? ? ? xValue: api.value(0) - 0.5,
? ? ? ? ? ? ? ? ? yValue: api.value(1),
? ? ? ? ? ? ? ? ? x: location[0],
? ? ? ? ? ? ? ? ? y: location[1]
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? style: api.style()
? ? ? ? ? ? ? },
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? type: 'MyCubeShadow',
? ? ? ? ? ? ? ? shape: {
? ? ? ? ? ? ? ? ? api,
? ? ? ? ? ? ? ? ? xValue: api.value(0) - 0.5,
? ? ? ? ? ? ? ? ? yValue: api.value(1),
? ? ? ? ? ? ? ? ? x: location[0],
? ? ? ? ? ? ? ? ? y: location[1]
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? style: {
? ? ? ? ? ? ? ? ? fill: api.style(),
? ? ? ? ? ? ? ? ? text: ''
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? }]
? ? ? ? ? ? }
? ? ? ? ? },
? ? ? ? ? stack: '單位面積能耗',
? ? ? ? ? label: {
? ? ? ? ? ? show: true,
? ? ? ? ? ? position: 'top',
? ? ? ? ? ? formatter: '{c}',
? ? ? ? ? ? textStyle: {
? ? ? ? ? ? ? fontSize: fontSize(12),
? ? ? ? ? ? ? color: '#fff',
? ? ? ? ? ? ? align: 'center'
? ? ? ? ? ? }
? ? ? ? ? },
? ? ? ? ? itemStyle: {
? ? ? ? ? ? color: new this.$echarts.graphic.LinearGradient(
? ? ? ? ? ? ? 0, 0, 0, 1,
? ? ? ? ? ? ? [
? ? ? ? ? ? ? ? { offset: 0, color: '#b1950d' },
? ? ? ? ? ? ? ? { offset: 0.5, color: '#aea20d' },
? ? ? ? ? ? ? ? { offset: 1, color: '#a5aa12' }
? ? ? ? ? ? ? ]
? ? ? ? ? ? )
? ? ? ? ? },
? ? ? ? ? data: [] //后端傳入數(shù)據(jù)
? ? ? ? }]
? ? ? }

注意事項(xiàng):

1)、在注冊(cè)圖形時(shí)style:只能使用 style: api.style();
text: ''后面才能使用label在圖形頂部放置value

2)、this.$echarts是經(jīng)過(guò)統(tǒng)一封裝之后的,具體情況還需具體考慮

(3)生成圖形

generateBarChart () {
? ? ? let vm = this
? ? ? if (this.$refs['uintEnergyConsume']) { //this.$refs是生成圖形區(qū)域的ref值
? ? ? ? this.$echarts.graphic.registerShape('MyCubeRect', this.MyCubeRect)
? ? ? ? this.$echarts.graphic.registerShape('MyCubeShadow', this.MyCubeShadow)
? ? ? ? this.barChart = this.$echarts.init(this.$refs['uintEnergyConsume'])
? ? ? ? this.barChart.setOption(this.barChartOption, false, true)
? ? ? ? $(window).resize(function () { //屏幕自適應(yīng)
? ? ? ? ? vm.handleResize()
? ? ? ? })
? ? ? }
? ? }

(4)template中代碼

<div ?ref="uintEnergyConsume" ?id="uintEnergyConsume" ?class="chart-container"?
?style="width: 100%;" ?element-loading-text="加載中..."></div>
</div>

(5)效果如下:

參考圖形網(wǎng)址:Vue使用Echarts實(shí)現(xiàn)立體柱狀圖

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 在 vue-cli v3.0 中使用 SCSS/SASS的方法

    在 vue-cli v3.0 中使用 SCSS/SASS的方法

    關(guān)于如何在 vue-cli v3.0 中使用 SCSS/SASS,這里提供三種方案。感興趣的朋友通過(guò)本文一起學(xué)習(xí)吧
    2018-06-06
  • 淺談VUE uni-app 條件編碼和頁(yè)面布局

    淺談VUE uni-app 條件編碼和頁(yè)面布局

    這篇文章主要介紹了uni-app 的條件編碼和頁(yè)面布局,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-10-10
  • Vue.js 父子組件通訊開(kāi)發(fā)實(shí)例

    Vue.js 父子組件通訊開(kāi)發(fā)實(shí)例

    這篇文章主要介紹了Vue.js 父子組件通訊開(kāi)發(fā)實(shí)例的相關(guān)資料,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-09-09
  • vue中beforeRouteLeave實(shí)現(xiàn)頁(yè)面回退不刷新的示例代碼

    vue中beforeRouteLeave實(shí)現(xiàn)頁(yè)面回退不刷新的示例代碼

    這篇文章主要介紹了vue中beforeRouteLeave實(shí)現(xiàn)頁(yè)面回退不刷新的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • vue服務(wù)端渲染添加緩存的方法

    vue服務(wù)端渲染添加緩存的方法

    vue服務(wù)區(qū)緩存分為頁(yè)面緩存、組建緩存和接口緩存,本文通過(guò)實(shí)例代碼逐一給大家介紹,本文重點(diǎn)給大家介紹vue服務(wù)端渲染添加緩存的方法,感興趣的朋友跟隨小編一起看看吧
    2018-09-09
  • vue3?中的toRef函數(shù)和toRefs函數(shù)的基本使用

    vue3?中的toRef函數(shù)和toRefs函數(shù)的基本使用

    這篇文章主要介紹了vue3?toRef函數(shù)和toRefs函數(shù),文中介紹了ref和toRef的區(qū)別,ref本質(zhì)是拷貝,修改響應(yīng)式數(shù)據(jù)不會(huì)影響原始數(shù)據(jù),toRef的本質(zhì)是引用關(guān)系,修改響應(yīng)式數(shù)據(jù)會(huì)影響原始數(shù)據(jù),需要的朋友可以參考下
    2022-11-11
  • vue輕松實(shí)現(xiàn)水印效果

    vue輕松實(shí)現(xiàn)水印效果

    這篇文章主要為大家詳細(xì)介紹了vue輕松實(shí)現(xiàn)水印效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Vue中keep-alive組件的深入理解

    Vue中keep-alive組件的深入理解

    這篇文章主要給大家介紹了關(guān)于Vue中keep-alive組件的深入理解,文中通過(guò)實(shí)例代碼結(jié)束的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • VueCli4項(xiàng)目配置反向代理proxy的方法步驟

    VueCli4項(xiàng)目配置反向代理proxy的方法步驟

    這篇文章主要介紹了VueCli4項(xiàng)目配置反向代理proxy的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Vue常見(jiàn)面試題整理【值得收藏】

    Vue常見(jiàn)面試題整理【值得收藏】

    本文是小編給大家收藏整理的Vue常見(jiàn)面試題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-09-09

最新評(píng)論