123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <template>
- <div ref="distion" style="width: 100%; height: 100%"></div>
- </template>
- <script>
- import * as echarts from "echarts";
- export default {
- props: {
- // className: {
- // type: String,
- // default: "chart",
- // },
- // width: {
- // type: String,
- // default: "100%",
- // },
- // height: {
- // type: String,
- // default: "400px",
- // },
- // perData: {
- // type: Array,
- // default: () => [
- // {
- // color: "#01ACFF",
- // name: "摄像头",
- // value: [39],
- // // nAmount: 566557.14,
- // },
- // ],
- // },
- },
- data() {
- return {};
- },
- mounted() {
- this.$nextTick(() => {
- this.initChart();
- });
- },
- beforeUnmount() {
- window.removeEventListener("resize", this.chart);
- },
- methods: {
- //次数分布折线图
- initChart() {
- var chart = echarts.init(this.$refs.distion);
- var option;
- var pie = [
- {
- value: 12,
- name: "配电",
- },
- {
- value: 5,
- name: "箱变",
- },
- {
- value: 3,
- name: "杆变",
- },
- ];
- var totalNum = 0;
- pie.forEach(function (value) {
- totalNum += value.value;
- });
- option = {
- grid: {
-
- },
- title: [
- {
- text: "{name|" + totalNum + "}\n{val|总数}",
- top: "center",
- left: "center",
- textStyle: {
- rich: {
- name: {
- fontSize: 30,
- fontWeight: "normal",
- color: "#FFFFFF",
- fontFamily:"impact",
- padding: [0, 0,3,0]
- },
- val: {
- fontSize: 14,
- fontWeight: "normal",
- color: "#FFFFFF",
- padding: [3,0,0, 0]
- },
- },
- },
- },
- ],
- tooltip: {
- // trigger: "item",
- trigger: 'item',
- confine:true,//将此限制打开后tooltip将不再溢出
- formatter: function (params) {
- return (
- params.name +
- ":" +
- params.value +
- "<br>占比:" +
- params.percent.toFixed(2) +
- "%"
- );
- },
- },
-
- series: [
- {
- label: {
- position: "inside",//此处将展示的文字在内部展示
- normal: {
- show: true,
- formatter: " {b}:{c} ",
- },
- emphasis: {
- show: true,
- },
- },
- name: "访问来源",
- radius: ["43%", "65%"],
- type: "pie",
- data: pie,
- labelLine: {
- normal: {
- length: 3, //aa折线长度
- // length2: 1, //aa折线长度
- }
- },
- // labelLine:{
- // normal:{
- // length:5
- // }
- // },
- },
- ],
- color: ["#39BBFE", "#FCCB35", "#FC7735"],
- };
- chart.setOption(option);
- window.addEventListener("resize", () => {
- chart.resize();
- });
- this.chart = chart;
- },
- },
- };
- </script>
|