zoukankan      html  css  js  c++  java
  • vue echart-demo

    <template>
    <div class="chart-bar-container" :id="id">
    </div>
    </template>

    <script>
    // import echarts from 'echarts'
    const echarts = require('echarts/lib/echarts')
    require('echarts/lib/chart/bar')
    require('echarts/lib/chart/pictorialBar')
    require('echarts/lib/component/tooltip')
    require('echarts/lib/component/title');

    export default {
    props: {
    pieData: {
    type:Number,
    default: 0
    }
    },
    data(){
    return {
    barGap: '10%',
    fillImg:'image://static/imgs/green.png'
    }
    },
    created() {
    this.id = 'chart' + (Math.random() + '').replace('.', '_')
    },
    mounted() {
    this.drawBar()
    },
    watch: {
    'pieData'() {
    if(this.pieData == 0){
    this.fillImg = 'image://static/imgs/green.png'
    }else{
    this.fillImg = 'image://static/imgs/red.png'
    }
    this.drawBar()
    },
    },
    methods: {
    drawBar() {
    let myChart = echarts.init(document.getElementById(this.id))
    let standard = 3, total = 6
    console.log(this.pieData)
    let option = {
    title: '',
    grid: {
    top: '15%',
    left: '15%',
    // right: '1%',
    // bottom: '15%',
    containLabel: true
    },
    tooltip: {
    trigger: 'axis',
    axisPointer: {
    type: 'none'
    },
    formatter: '{a}',
    },
    xAxis: {
    type: 'category',
    show: false,
    },
    yAxis: {
    name: '值',
    show: false,
    offset: 52,
    splitNumber: 4,
    splitLine: {
    show: false,
    },
    nameTextStyle:{
    color: '#fff'
    },
    axisTick: {
    show: false
    },
    axisLine: {
    show: true
    },
    axisLabel: {
    show: true,
    color: '#fff'
    }
    },
    color: '#e54035',
    series: {
    name: '风险值3',
    type: 'pictorialBar',
    barCategoryGap: this.barGap,
    symbol: this.fillImg,
    // symbol: 'path://d="M150 50 L130 130 L170 130 Z"', //三角形
    // itemStyle: {
    // normal: {
    // color: function(params) {
    // let colorList = [
    // 'rgba(13,177,205,0.8)', 'rgba(29,103,182,0.6)',
    // 'rgba(13,177,205,0.8)', 'rgba(29,103,182,0.6)',
    // 'rgba(13,177,205,0.8)', 'rgba(29,103,182,0.6)'
    // ];
    // return colorList[params.dataIndex];
    // }
    // },
    // emphasis: {
    // opacity: 1
    // }
    // },
    label: {
    show: true,
    position: 'top',
    color:'#fff',
    formatter: '{c}',
    },
    data: [6],
    },
    }
    myChart.setOption(option)
    window.addEventListener('resize', function() {
    myChart.resize()
    })
    }
    }
    };
    </script>

    <style lang="stylus" scoped rel="stylesheet/stylus">
    .chart-bar-container
    100%
    height:100%
    </style>

  • 相关阅读:
    August 4th, 2016, Week 32nd, Thursday
    August 3rd, 2016, Week 32nd, Wednesday
    Java的垃圾回收机制
    学java入门到精通,不得不看的15本书
    java中set和get方法的理解
    eclipse快捷键
    main方法无法编译
    Java构造器和方法的区别
    交换两个变量的值,不使用第三个变量
    计算圆周率 Pi (π)值, 精确到小数点后 10000 位 只需要 30 多句代码
  • 原文地址:https://www.cnblogs.com/dmwcq/p/9717297.html
Copyright © 2011-2022 走看看