123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <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: "double-line-chart",
- componentName: "double-line-chart",
- props: {
- isChartClick:{
- type: Boolean,
- default: false,
- },
- width: {
- type: String,
- default: "100%",
- },
- height: {
- type: String,
- default: "13.889vh",
- },
- // 传入数据
- list: {
- type: Array,
- default: () => [
- {
- title: "绿线",
- value: [
- {
- text: "",
- value: 0,
- },
- {
- text: "0:00",
- value: 20,
- },
- {
- text: "10:00",
- value: 1,
- },
- {
- text: "11:00",
- value: 40,
- },
- {
- text: "12:00",
- value: 10,
- },
- {
- text: "13:00",
- value: 15,
- },
- {
- text: "14:00",
- value: 30,
- },
- {
- text: "15:00",
- value: 40,
- },
- {
- text: "",
- value: 10,
- },
- ],
- },
- {
- title: "黄线",
- value: [
- {
- text: "",
- value: 0,
- },
- {
- text: "0:00",
- value: 40,
- },
- {
- text: "10:00",
- value: 20,
- },
- {
- text: "11:00",
- value: 20,
- },
- {
- text: "12:00",
- value: 10,
- },
- {
- text: "13:00",
- value: 40,
- },
- {
- text: "14:00",
- value: 50,
- },
- {
- text: "15:00",
- value: 40,
- },
- {
- text: "",
- value: 10,
- },
- ],
- },
- ],
- },
- // 单位
- unit: {
- type: String,
- default: "MW",
- },
- showLegend: {
- type: Boolean,
- default: false,
- },
- },
- data() {
- return {
- id: "",
- chart: null,
- color: ["#05bb4c", "#f8de5b", "#4b55ae", "#fa8c16"],
- };
- },
- computed: {
- colorValue() {
- return partten.getColor(this.color);
- },
- datas() {
- return this.list.map((t) => {
- return t.value;
- });
- },
- legend() {
- return this.list.map((t) => {
- return t.title;
- });
- },
- xdata() {
- return this.list[0].value.map((t) => {
- return t.text;
- });
- },
- series() {
- let that = this;
- let result = [];
- this.list.forEach((value, index) => {
- result.push({
- name: value.title,
- type: "line",
- smooth: true,
- showSymbol: false,
- zlevel: index,
- lineStyle: {
- normal: {
- color: this.color[index],
- width: 1,
- },
- },
- markPoint: {},
- // index == 0
- // ? {
- // data: [
- // {
- // type: "average",
- // name: "保证功率",
- // symbolSize: 0,
- // label: {
- // offset: [0, -40],
- // formatter: function(param) {
- // return `{title|${param.name}}` + "\n" + `{value| ${param.value}${that.unit}}`;
- // },
- // backgroundColor: partten.getColor("green") + 33,
- // borderColor: partten.getColor("green"),
- // borderWidth: 0.5,
- // borderRadius: 2,
- // padding: 8,
- // rich: {
- // title: {
- // color: partten.getColor("green"),
- // fontSize: 12,
- // },
- // value: {
- // color: "#fff",
- // fontSize: 16,
- // padding: [12, 0, 0, -4],
- // },
- // },
- // },
- // },
- // ],
- // }
- // : {},
- yAxisIndex: value.yAxisIndex,
- data: value.value.map((t) => {
- return t.value;
- }),
- });
- });
- return result;
- },
- yAxis() {
- let result = [];
- result.push({
- type: "value",
- name: this.unit,
- axisLabel: {
- formatter: "{value}",
- fontSize: util.vh(14),
- },
- boundaryGap: false,
- //分格线
- splitLine: {
- show: true,
- lineStyle: {
- color: partten.getColor("gray"),
- type: "dashed",
- },
- },
- });
- return result;
- },
- },
- methods: {
- resize() {},
- initChart() {
- let that = this;
- const chart = echarts.init(this.$el);
- let option = {
- color: this.color,
- tooltip: {
- trigger: "axis",
- backgroundColor: "rgba(0,0,0,0.4)",
- borderColor: partten.getColor("gray"),
- textStyle: {
- color: "#fff",
- fontSize: util.vh(16),
- },
- },
- legend: {
- show: this.showLegend,
- data: this.legend,
- right: 56,
- icon: "circle",
- itemWidth: 6,
- inactiveColor: partten.getColor("gray"),
- textStyle: {
- color: partten.getColor("grayl"),
- fontSize: 12,
- },
- },
- grid: {
- top: 16,
- left: 32,
- right: 8,
- bottom: 24,
- },
- xAxis: [
- {
- type: "category",
- boundaryGap: false,
- axisLabel: {
- formatter: "{value}",
- textStyle: {
- color: partten.getColor("gray"),
- fontSize: util.vh(14),
- },
- },
- data: this.xdata,
- },
- ],
- yAxis: this.yAxis,
- series: this.series,
- };
- chart.clear();
- chart.setOption(option);
- if(this.isChartClick){
- chart.getZr().off("click");
- chart.getZr().on("click", (params) => {
- that.chartClick();
- });
- }
- this.resize = function() {
- chart.resize();
- };
- window.addEventListener("resize", this.resize);
- },
- chartClick(){
- this.$emit("chartClick");
- }
- },
- 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();
- });
- },
- unmounted() {
- window.removeEventListener("resize", this.resize);
- },
- };
- </script>
- <style lang="less">
- .chart {
- width: 100%;
- height: 100%;
- display: inline-block;
- }
- </style>
|