Search code examples
javascriptvue.jsvuejs2echarts

Vue: vue-echarts not rendered


I am creating a simple bar chart using vue-echart and Vue 2. I want to display a bar chart from Comp1.vue inside my home page, App.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>

I have imported all the possible dependencies but the chart is not rendered. I have no idea how this could happen. How should I solve this so that the chart gets rendered?


Solution

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

    I believe here should be option instead of options. According to the readme