iT邦幫忙

0

如何使用vue2元件props傳資料 並用echarts顯示資料

  • 分享至 

  • xImage

大家好~想請問
我用echarts做圖表 用vue套資料
發現在內層資料傳到外層後就是空的(1.程式碼資料傳到2.)
不知道傳送資料時哪邊要修改

https://ithelp.ithome.com.tw/upload/images/20220819/20147822RfHPkt3EJR.jpg

<template>
    <div class="card">
        <div class="card-body">
            <h5 class="card-title">
                <div class="card-titleCenter">急診檢傷人數(本事件)</div>
                <div class="card-titleBottom">
                    <span class="block_DateRange">
                        <date-picker-range @change-date="changeDate">
                        </date-picker-range>
                    </span>
                </div>
            </h5>
            <div class="card-content">
                <stack-bar01 :five-Level-Obj="fiveLevelObj"></stack-bar01>
            </div>
        </div>
    </div>
</template>

<script>
//自定義元件
import DatePickerRange from "@/components/DatePickerRange";
import StackBar01 from "./components/StackBar01";

//api
import PatientStatusResource from "@/api/jie-qiao/patient-status";

//套件
import moment from "moment";

const patientStatusResource = new PatientStatusResource();

export default {
    name: "FiveLevelBlock",
    components: { DatePickerRange, StackBar01 },
    props: {},
    data() {
        return {
            fiveLevelObj: [],
            filterFormData: {
                StartDate: moment().locale("zh-tw").format("YYYY-MM-DD"),
                EndDate: moment().locale("zh-tw").format("YYYY-MM-DD"),
            },
        };
    },
    computed: {},
    created() {},
    mounted() {
        this.init();
    },
    methods: {
        async getFiveLevelList() {
            const fiveLevelObj = await patientStatusResource.fiveLevelList(
                this.filterFormData
            );
            fiveLevelObj &&
                this.$set(this, "fiveLevelObj", fiveLevelObj);
            console.log("---- 輸入標題 -----");
            console.log(fiveLevelObj);
            console.log("---- 輸入結尾 -----");
        },
        init() {
            this.$nextTick(() => {
                this.getFiveLevelList();
            });
        },
        changeDate(date) {
            this.filterFormData.StartDate = date[0];
            this.filterFormData.EndDate = date[1];
            this.init();
        },
    },
    watch: {},
};
</script>

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

<template>
    <div
        class="ac_chartBlock"
        id="acChart01"
        style="width: 100%; height: 800px"
    ></div>
</template>

<script>
//echarts套件
const acPieChart = {
    ...
};

export default {
    name: "StackBar01",
    components: {},
    props: {
        fiveLevelObj: {
            type: Object,
        },
    },
    data() {
        return {
            acPieChart: acPieChart,
        };
    },
    computed: {},
    created() {},
    mounted() {
        const acChart01 = echarts.init(document.getElementById("acChart01"));
        acChart01.setOption(acPieChart);
            // console.log('---- 輸入標題 -----')
            // console.log(fiveLevelObj);
            // console.log('---- 輸入結尾 -----')
        },
    methods: {},
    watch: {
        fiveLevelObj: {
            handler(newValue, oldValue) {
                const acChart01 = echarts.init(
                    document.getElementById("acChart01")
                );
                for (let i = 0; i < 5; i++) {
                    this.acPieChart.series[i].data = [];
                    this.acPieChart.series[i].data = _(this.fiveLevelObj)
                        .map(`chK_LEVEL${i + 1}`)
                        .value();
                }
                acChart01.setOption(this.acPieChart);
            },
            deep: true,
        },
    },
};
</script>

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

圖片!!!我先跳過了。
淺水員 iT邦大師 6 級 ‧ 2022-08-20 09:35:42 檢舉
可參考下圖貼程式碼
https://ithelp.ithome.com.tw/upload/images/20220506/20112943CaY46NCTvh.png
碼農 iT邦新手 4 級 ‧ 2022-08-21 22:40:46 檢舉
感謝兩位大大提醒
原來不能用圖片問~抱歉
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答