Vue:vue-echarts未呈现

8ehkhllq  于 2023-08-07  发布在  Vue.js
关注(0)|答案(2)|浏览(121)

我正在使用vue-echart和Vue 2创建一个简单的条形图。我想在我的主页App. vue中显示Comp1.vue的条形图。
App.vue

<template>
  <div id="app">
    <Comp1/>
  </div>
</template>

<script>
import Comp1 from './components/Comp1.vue'

export default {
  name: 'App',
  components: {
    Comp1
  }
}
</script>

<style>
</style>

字符串
main.js

import Vue from 'vue'
import App from './App.vue'
import VueECharts from "vue-echarts";
import "@vue/composition-api";
import "echarts";

Vue.config.productionTip = false

Vue.component("v-chart", VueECharts);

new Vue({
  VueECharts,
  render: h => h(App),
}).$mount('#app')


Comp1.vue

<template>
<div style="height: 300px;">
    <v-chart :options="chartOptionsBar"></v-chart>
    Yes
</div>
</template>

<script>
export default {
  name: 'Comp1',
  data() {
      return {
        chartOptionsBar: {
        xAxis: {
            data: ['Latte', 'Espresso', 'Mocha', 'Cappucino']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
            type: 'bar',
            data: [100, 50, 25, 10]
            }
        ]
        }
      }
  }
}
</script>

<style scoped>
</style>


我已经导入了所有可能的依赖项,但图表没有呈现。我不知道怎么会这样。我应该如何解决这个问题,使图表得到渲染?

ncgqoxb0

ncgqoxb01#

<v-chart :options="chartOptionsBar"></v-chart>

字符串
我认为这里应该是选项而不是选项。根据readme

xvw2m8pv

xvw2m8pv2#

解决方案

我遇到了同样的问题。解决方案是你必须使用“echarts/components”中的“GridComponent”。给予图表x,y轴..
最终代码应该是这样的:

<script lang="ts">
import { use } from "echarts/core";
import { SVGRenderer } from "echarts/renderers";
import { BarChart } from "echarts/charts";
import { GridComponent } from "echarts/components";
import VChart, { THEME_KEY } from "vue-echarts";
import { provide, ref } from "vue";

export default {
  name: "BarChart",
  components: { VChart },
  setup() {
    use([SVGRenderer, BarChart, GridComponent]);

    provide(THEME_KEY, "dark");

    const option = ref({
      xAxis: {
        type: "category",
        data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
      },
      yAxis: {
        type: "value",
      },
      series: [
        {
          data: [120, 200, 150, 80, 70, 110, 130],
          type: "bar",
        },
      ],
    });

    return {
      option,
    };
  },
};
</script>

<template lang="pug">
.q
  v-chart(class="chart" :option="option")
</template>

<style scoped lang="sass">
.chart
  height: 300px
</style>

字符串

*要了解更多信息,请访问并按照此处的说明操作:https://echarts.apache.org/examples/en/editor.html?c=bar-simple&theme=dark

相关问题