vue echarts3


安装echarts

cnpm install --save vue-echarts-v3

新建一个一个通用的折线图组件  line.vue

<template>
    <div id="line">
    	<IEcharts :option="line" :style="style"></IEcharts>
    </div>
</template>

<script>
import IEcharts from 'vue-echarts-v3' // 导入IEcharts组件
export default {
  props: {
    obj: null
  },
  data () {
    return {
      line: {
        tooltip: {
          trigger: 'axis'
        },
        xAxis: { // 横坐标
          boundaryGap: false,
          data: this.obj.xAxis // 横坐标数据
        },
        yAxis: { // 纵坐标
        },
        series: [
          {
            name: '查询条数',
            type: 'line', // 图表类型
            data: this.obj.series // 纵坐标数据
          }
        ]
      },
      style: 'width:890px;height:500px;'
    }
  },
  components: {
    IEcharts// 声明组件
  }
}
</script>


父页面使用

<template>
<!--  :obj向子页面传值-->
  <detailedAll :obj="data"></detailedAll>
</template>

<script>
import line from '@/components/echarts/line.vue' // 引用line
export default {
  data () {
    return {
      data: null
    }
  },
  methods: {
// 图表
    detailedtab () {
      let that = this
      that.data = null
      let params = {}
      that.$api.get('###', params, function (req) {
        that.data = req.content
      })
    }
  },
  components: {
    detailedAll: line // 自定义组件
  }
}
</script>





### Vue 中使用 ECharts 实现 3D 环形图 为了在 Vue 应用程序中实现 3D 环形图,需先安装并引入必要的依赖库。确保已成功集成 ECharts 和其扩展 `echarts-gl` 来支持三维图形渲染。 #### 安装依赖包 通过 npm 或 yarn 安装所需模块: ```bash npm install echarts echarts-gl --save ``` 或 ```bash yarn add echarts echarts-gl ``` #### 创建组件结构 创建一个新的 Vue 组件用于展示 3D 环形图,并导入所需的 JavaScript 文件来加载 ECharts 及其 GL 扩展功能[^1]。 ```javascript // MyPie3DChart.vue <template> <div ref="chartContainer" style="width: 600px; height: 400px;"></div> </template> <script> import * as echarts from &#39;echarts&#39;; require(&#39;echarts-gl&#39;); export default { mounted() { this.initChart(); }, methods: { initChart() { const chartDom = this.$refs.chartContainer; const myChart = echarts.init(chartDom); let option; // 配置项和数据源定义如下... option = { title: { text: &#39;3D Ring Chart&#39;, subtext: &#39;&#39;, left: &#39;center&#39; }, tooltip: { trigger: &#39;item&#39; }, series: [ { type: &#39;pie&#39;, radius: [&#39;40%&#39;, &#39;70%&#39;], itemStyle: { borderRadius: 8, borderColor: &#39;#fff&#39;, borderWidth: 2 }, data: [ { value: 10, name: &#39;Category A&#39; }, { value: 15, name: &#39;Category B&#39; }, { value: 20, name: &#39;Category C&#39; } ] } ], grid3D: {}, xAxis3D: {}, yAxis3D: {}, zAxis3D: {} }; function renderItem(params, api) { var categoryIndex = api.value(0); var start = api.coord([api.value(1), api.value(2)]); var end = api.coord([api.value(3), api.value(4)]); return { type: &#39;arc3D&#39;, shape: { cx: (start[0] + end[0]) / 2, cy: (start[1] + end[1]) / 2, cz: params.seriesId === "ring" ? Math.sin(categoryIndex * Math.PI / 9) : 0, rx: Math.abs(end[0] - start[0]) / 2, ry: Math.abs(end[1] - start[1]) / 2, rz: .5, startAngle: 0, endAngle: 2 * Math.PI }, style: api.style() }; } option.series.push({ id: &#39;ring&#39;, type: &#39;custom&#39;, coordinateSystem: &#39;none&#39;, renderItem: renderItem, encode: { itemName: 0, value: 2 }, dimensions: ["category", "startX", "startY", "endX", "endY"], data: [ [0, 0, 0, 0, 1], [1, 0, 1, 1, 2], [2, 1, 2, 2, 3] ].map(function(item) { return [ item[0], ((item[1] % 3) - 1) * 40, ((Math.floor(item[1] / 3)) * 40), ((item[3] % 3) - 1) * 40, ((Math.floor(item[3] / 3)) * 40) ]; }) }); myChart.setOption(option); } } }; </script> ``` 这段代码展示了如何构建一个简单的 3D 环形图实例,在实际应用中可能还需要调整样式和其他配置参数以满足具体需求[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值