Code Monkey home page Code Monkey logo

Comments (3)

xlsdg avatar xlsdg commented on May 18, 2024

参考 #39 获取 echarts 对象。

from vue-echarts-v3.

spikespiegel5112 avatar spikespiegel5112 commented on May 18, 2024

我现在定义一个函数,里面放了全部的图标设置参数,然后赋给data中的一个变量,比如叫bar:{},结果不会报错了,但是我想给图表加的渐变色总是加不上去,图表一直显示红色,下面是我设置图表的代码

<template>
    <div>
        <div class="chart">
            <label>{{title}}</label>
            <IEcharts :option="bar" :loading="loadingFlag" @ready="onReady"></IEcharts>
        </div>
    </div>
</template>
<script>
    import IEcharts from 'vue-echarts-v3/src/full.vue';

    var data = {
        name: ['党政', '经济', '农业', '政法', '信访', '扶贫', '财贸'],
        value: [1, 3, 5, 7, 9, 11, 13],
    };
    export default {
        props: ['title', 'chartData'],
        data() {
            return {
                loadingFlag: true,
                bar: {}
            }
        },
        components: {
            IEcharts
        },
        mounted() {
        },
        methods: {
            onReady(instance, echarts) {
                this.loadingFlag = false;
                console.log(echarts)
                this.getOptions(echarts)
            },
            getOptions(echarts){
                let options = {
                    xAxis: {
                        data: data.name,
                        axisLabel: {
                            inside: false,
                            textStyle: {
                                interval: 0,
                                color: '#fff',
                                fontSize: 12
                            }
                        },
                        axisTick: {
                            show: false
                        },
                        axisLine: {
                            show: false
                        },
                        z: 10
                    },
                    yAxis: {
                        axisLine: {
                            show: false
                        },
                        axisTick: {
                            show: false
                        },
                        axisLabel: {
                            textStyle: {
                                color: '#999'
                            }
                        }
                    },
                    dataZoom: [
                        {
                            type: 'inside'
                        }
                    ],
                    series: [
                        {
                            type: 'bar',
                            itemStyle: {
                                normal: {
                                    color: echarts.graphic.LinearGradient(
                                        0, 0, 0, 1,
                                        [
                                            {offset: 0, color: '#fff'},
                                            {offset: 1, color: '#000'}
                                        ]
                                    )
                                }
                            },
                            label: {
                                normal: {
                                    fontWeight: 'bolder',
                                    fontSize: 23
                                }
                            },
                            barWidth: 20,
                            data: data.value
                        }
                    ]
                }
                this.bar = options;
                return options;
            }
        }
    }
</script>

from vue-echarts-v3.

xlsdg avatar xlsdg commented on May 18, 2024
<template>
  <div class="echarts">
    <IEcharts :option="bar" @ready="onReady" />
  </div>
</template>

<script>
import IEcharts from 'vue-echarts-v3/src/full.vue'

export default {
  name: 'view',
  components: {
    IEcharts
  },
  data () {
    // const that = this
    return {
      ins: null,
      echarts: null,
      bar: {}
    }
  },
  methods: {
    onReady (instance, echarts) {
      const that = this
      that.ins = instance
      that.echarts = echarts

      that.bar = {
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],
          axisLabel: {
            inside: false,
            textStyle: {
              interval: 0,
              color: '#fff',
              fontSize: 12
            }
          },
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          },
          z: 10
        },
        yAxis: {
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            textStyle: {
              color: '#999'
            }
          }
        },
        dataZoom: [
          {
            type: 'inside'
          }
        ],
        series: [
          {
            type: 'bar',
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0, 0, 0, 1,
                  [
                    { offset: 0, color: '#fff' },
                    { offset: 1, color: '#000' }
                  ]
                )
              }
            },
            label: {
              normal: {
                fontWeight: 'bolder',
                fontSize: 23
              }
            },
            barWidth: 20,
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      }
    }
  }
  // beforeMount () {
  //   const that = this
  // },
  // mounted () {
  //   const that = this
  // },
  // beforeDestroy () {
  //   const that = this
  // }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.echarts {
  width: 800px;
  height: 800px;
}
</style>

from vue-echarts-v3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.