123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <template>
- <div class="chart" :id="id"></div>
- </template>
- <script>
- import util from "@/helper/util.js";
- import partten from "@/helper/partten.js";
- import * as echarts from "echarts";
- export default {
- name: "percent-pie",
- componentName: "percent-pie",
- props: {
- width: {
- type: String,
- default: "18.519vh",
- },
- height: {
- type: String,
- default: "18.519vh",
- },
- // 百分比值
- value: {
- type: Number,
- default: 10,
- },
- max: {
- type: Number,
- default: 100,
- },
- // 颜色 green yellow 等 partten支持的颜色
- color: {
- type: String,
- default: "green",
- },
- },
- data() {
- return {
- id: "",
- chart: null,
- };
- },
- computed: {
- colorValue() {
- return partten.getColor(this.color);
- },
- },
- methods: {
- initChart() {
- let option = {
- calculable: true,
- series: [
- {
- name: "",
- type: "pie",
- radius: ["0%", "100%"],
- center: ["50%", "50%"],
- data: [
- {
- value: this.value,
- name: "",
- itemStyle: {
- color: this.colorValue,
- },
- },
- {
- value: this.max - this.value,
- name: "",
- itemStyle: {
- color: "transparent",
- },
- },
- ],
- label: {
- show: false,
- position: "center",
- },
- },
- {
- name: "",
- type: "pie",
- radius: ["0%", "95%"],
- center: ["50%", "50%"],
- data: [
- {
- value: this.value,
- name: "",
- itemStyle: {
- color: "transparent",
- },
- },
- {
- value: this.max - this.value,
- name: "",
- itemStyle: {
- color: "#5f6769",
- },
- },
- ],
- label: {
- show: false,
- position: "center",
- },
- },
- ],
- };
- this.chart.setOption(option);
- },
- },
- created() {
- this.id = "pie-chart-" + util.newGUID();
- },
- mounted() {
- this.$el.style.width = this.width;
- this.$el.style.height = this.height;
- this.chart = echarts.init(this.$el);
- this.initChart();
- },
- updated() {
- this.initChart();
- },
- };
- </script>
- <style lang="less">
- .chart {
- width: 100%;
- height: 100%;
- display: inline-block;
- }
- </style>
|