<template>
    <div class="crop_chart_c">
        <div id="crop_chart_c" style="width: 100%;height:400px;"></div>
    </div>
</template>

<script>
export default {
    name: "crop_chart_c",
    props: {},
    data() {
        return {};
    },
    created() {},
    mounted() {
        this.drawChart();
    },
    methods: {
        drawChart() {
            // 基于准备好的dom，初始化echarts实例
            let myChart = this.$echarts.init(
                document.getElementById("crop_chart_c")
            );
            // 指定图表的配置项和数据
            let option = {
                title: {
                    text: "未来保育猪数量预测",
                    left: "center",
                    bottom: 5
                },
                color: ["#3398DB"],
                tooltip: {
                    trigger: "axis",
                    axisPointer: {
                        // 坐标轴指示器，坐标轴触发有效
                        type: "line" // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                toolbox: {
                    show: true,
                    feature: {
                        dataView: { show: true, readOnly: true },
                        magicType: { show: true, type: ["line", "bar"] },
                        restore: { show: true },
                        saveAsImage: { show: true }
                    }
                },
                grid: {
                    left: "10%",
                    right: "10%",
                    bottom: "13%",
                    containLabel: true
                },
                xAxis: [
                    {
                        type: "category",
                        data: [
                            "七月",
                            "八月",
                            "九月",
                            "十月",
                            "十一月",
                            "十二月"
                        ],
                        axisTick: {
                            alignWithLabel: true
                        }
                    }
                ],
                yAxis: [
                    {
                        type: "value"
                    }
                ],
                series: [
                    {
                        name: "数量",
                        type: "bar",
                        barWidth: "50%",
                        data: [355, 200, 422, 390, 330, 220],
                        encode: {
                            // Map the "amount" column to X axis.
                            x: "amount",
                            // Map the "product" column to Y axis
                            y: "product"
                        },
                        markPoint: {
                            data: [
                                { type: "max", name: "最大值" },
                                { type: "min", name: "最小值" }
                            ]
                        },
                        markLine: {
                            data: [{ type: "average", name: "平均值" }]
                        }
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
    }
};
</script>

<style lang="scss" scoped>
</style>