<el-dropdown-menu slot="dropdown"> <el-dropdown-item v-for="item in options" :key="item.name" ><el-checkBox v-model="item.ischeck" @change="test(item)">{{ item.label }}</el-checkBox></el-dropdown-item > </el-dropdown-menu> </el-dropdown> </div> </div> </template> <script> const cityOptions = ["上海", "北京", "广州", "深圳"]; import * as echarts from "echarts"; export default { name: "time-demo", data() { return { checkAll: false, checkedCities: ["上海", "北京"], cities: cityOptions, isIndeterminate: true, myChartInstance: {}, options: [ { ischeck: true, label: "all", }, { ischeck: true, label: "2015", }, { ischeck: true, label: "2016", }, { ischeck: true, label: "2017", }, ], }; }, mounted() { this.buildCharts(); }, methods: { test(d) { var testd = this.myChartInstance; if (d.label === "all" && d.ischeck) { this.options.forEach(function (item) { item.ischeck = true; }); testd.dispatchAction({ type: "legendAllSelect", }); } else if (d.label === "all" && !d.ischeck) { testd.dispatchAction({ type: "legendAllSelect", }); testd.dispatchAction({ type: "legendInverseSelect", }); this.options.forEach(function (item) { item.ischeck = false; }); } else { testd.dispatchAction({ type: "legendToggleSelect", name: d.label, });
var array = this.options; console.log(d); var count1 = 0; var count2 = 0; for (let index = 1; index < array.length; index++) { const element = array[index]; if (element.ischeck) { count1++; } else { count2++; } } if (count1 == array.length - 1) { this.options[0].ischeck = true; } if (count2 == array.length - 1) { this.options[0].ischeck = false; } } }, buildCharts() { console.log(this.$refs.main); var myChart = echarts.init(this.$refs.main); this.myChartInstance = myChart; // 绘制图表 myChart.setoption({ legend: {}, tooltip: {}, dataset: { source: [ ["product", "2015", "2016", "2017"], ["Matcha Latte", 43.3, 85.8, 93.7], ["Milk Tea", 83.1, 73.4, 55.1], ["Cheese Cocoa", 86.4, 65.2, 82.5], ["Walnut brownie", 72.4, 53.9, 39.1], ], }, xAxis: { type: "category" }, yAxis: {}, // Declare several bar series, each will be mapped // to a column of dataset.source by default. series: [{ type: "bar" }, { type: "bar" }, { type: "bar" }], }); }, }, }; </script> <style> #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。