<template>
    <div class="moneyCompare">
        <canvas class="compare" canvas-id="compare" id="compare"/>
    </div>
</template>

<script>
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
    name: "moneyCompare",
    data() {
        return {
            width:0
        }
    },
    props: {
        data: {
            type: Object,
            default: () => {}
        }
    },
    watch: {
        data: {
            handler(value) {
                console.log('carDatawatch', value)
                this.handleCarData(value)
            }
        }
    },
    methods: {
        // 处理传入的数据
        handleCarData(value) {
            let res = value
            this.drawCharts('compare', res)
        },
        drawCharts(id, data) {
            const ctx = uni.createCanvasContext(id, this);
            let _this = this
            let phoneInfo = uni.getStorageSync('phoneInfo')
            this.width = phoneInfo.screenWidth - 16
            uChartsInstance[id] = new uCharts({
                type: "column",
                context: ctx,
                width: _this.width,
                height: 208,
                categories: data.categories,
                series: data.series,
                animation: true,
                rotate: false,
                rotateLock: false,
                background: "#FFFFFF",
                color: ["#CAD0DA", "#1E80FF"],
                padding: [15, 40, 5, 0],
                dataLabel: false,
                enableScroll: false,
                legend: {
                    show: true,
                    position: "bottom",
                    lineHeight: 25,
                    float: 'center'

                },
                xAxis: {
                    disableGrid: true
                },
                yAxis: {
                    showTitle:true,
                    splitNumber:4,
                    data: [
                        {
                            min: 0,
                            max: 12,
                            title:'单位: 千万',
                            titleOffsetX:5,
                            titleOffsetY:-5
                        }
                    ]
                },
                extra: {
                    column: {
                        type: "group",
                        width: 5,
                        activeBgColor: "#000000",
                        activeBgOpacity: 0.08
                    }
                }
            });
        },
    }
}
</script>

<style scoped lang="scss">
.moneyCompare{
    width: 100%;
    .compare{
        width: calc(100vw - 32px);
        height: 200px;
    }
}
</style>