123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <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: "multiple-bar-chart",
- componentName: "multiple-bar-chart",
- props: {
- width: {
- type: String,
- default: "100%",
- },
- height: {
- type: String,
- default: "800px",
- },
- // 传入数据
- bardata: {
- type: Object,
- default: () => {
- return {
- area: ["风场1", "风场2", "风场3", "风场4", "风场5", "风场6", "风场7", "风场8", "风场9"],
- legend: ["实际电量", "计划检修损失", "非计划检修损失", "限电损失", "受累损失", "性能损失"],
- data: [
- [1320, 1302, 901, 634, 1390, 1330, 1320, 1000, 500],
- [320, 302, 301, 334, 390, 330, 320, 100, 50],
- [320, 302, 301, 334, 390, 330, 320, 100, 50],
- [1320, 1302, 901, 634, 1390, 1330, 1320, 1000, 500],
- [320, 302, 301, 334, 390, 330, 320, 100, 50],
- [320, 302, 301, 334, 390, 330, 320, 100, 50],
- [1320, 1302, 901, 634, 1390, 1330, 1320, 1000, 500],
- [320, 302, 301, 334, 390, 330, 320, 100, 50],
- ],
- };
- },
- },
- lineData: {
- type: Array,
- default: () => [200, 350, 400, 500, 600, 700, 800, 900, 1200],
- },
- // 单位
- units: {
- type: Array,
- default: () => ["健康趋势", "风机健康状态数量"],
- },
- // 显示 legend
- showLegend: {
- type: Boolean,
- default: true,
- },
- // 颜色
- color: {
- type: Array,
- default: () => ["#05bb4c", "#4b55ae", "#e17e23", "#02BB4C", "#EDB32F", "#EDEB2F"],
- },
- },
- data() {
- return {
- id: "",
- chart: null,
- };
- },
- computed: {
- legend() {
- return this.bardata.legend;
- },
- },
- methods: {
- initChart() {
- let chart = echarts.init(this.$el);
- let option = {
- color: this.color,
- grid: {
- left: 16,
- right: 16,
- bottom: 0,
- top: 32,
- containLabel: true,
- },
- tooltip: {
- trigger: "axis",
- backgroundColor: "rgba(0,0,0,0.4)",
- textStyle: {
- color: "#fff",
- fontSize: 14,
- },
- },
- legend: {
- show: this.showLegend,
- data: this.bardata.legend,
- right: 120,
- icon: "ract",
- itemWidth: 8,
- itemHeight: 8,
- inactiveColor: partten.getColor("gray"),
- textStyle: {
- color: partten.getColor("grayl"),
- fontSize: 12,
- },
- },
- xAxis: [
- {
- type: "category",
- axisLabel: {
- color: partten.getColor("gray"),
- },
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- data: this.bardata.area,
- },
- ],
- yAxis: [
- {
- type: "value",
- name: this.units[0],
- axisLabel: {
- formatter: "{value} ",
- color: partten.getColor("gray"),
- },
- axisLine: {
- type: "dashed",
- lineStyle: {
- color: partten.getColor("gray"),
- },
- width: 5,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- lineStyle: {
- type: "dashed",
- dashOffset: 10,
- color: partten.getColor("gray") + 80,
- },
- },
- },
- {
- type: "value",
- name: this.units[1],
- axisLabel: {
- formatter: "{value} ",
- color: partten.getColor("gray"),
- align: "left",
- },
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- },
- ],
- series: [],
- };
- // line data
- if (this.lineData.length > 0) {
- option.series.push({
- name: this.units[0],
- type: "line",
- data: this.lineData,
- smooth: false, //平滑展示
- yAxisIndex: 0,
- lineStyle: {
- // color: partten.getColor("green"),
- color: "#323E6F",
- },
- itemStyle: {
- // color: partten.getColor("green"),
- color: "#323E6F",
- },
- });
- }
- // bar data
- for (var i = 0; i < this.bardata.legend.length; i++) {
- option.series.push({
- name: this.bardata.legend[i],
- type: "bar",
- stack: "总量",
- yAxisIndex: 1,
- // barWidth: "60%",
- label: {
- show: false,
- position: "insideRight",
- },
- data: this.bardata.data[i],
- });
- }
- chart.setOption(option);
- },
- },
- created() {
- this.id = "pie-chart-" + util.newGUID();
- },
- mounted() {
- this.$nextTick(() => {
- this.$el.style.width = this.width;
- this.$el.style.height = this.height;
- this.initChart();
- });
- },
- updated() {
- this.$nextTick(() => {
- this.initChart();
- });
- },
- };
- </script>
- <style lang="less">
- .chart {
- width: 100%;
- height: 100%;
- display: inline-block;
- }
- </style>
|