123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <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";
- import { right } from "@antv/x6/lib/registry/port-layout/main";
- export default {
- name: "multiple-line-chart",
- componentName: "multiple-line-chart",
- props: {
- width: {
- type: String,
- default: "100%",
- },
- height: {
- type: String,
- default: "100%",
- },
- chartData: {
- type: Array,
- default: () => {},
- },
- isDouble: { type: Boolean, default: false },
- type: { type: String, default: "" },
- },
- data() {
- return {
- id: "",
- chart: null,
- chartName: [
- { name: "实际功率", code: "sjgl", color: "#4B55AE" },
- { name: "理论功率", code: "llgl", color: "#1C99FF" },
- { name: "预测功率", code: "ycgl", color: "#F8DE5B" },
- { name: "实际风速", name1: "实际光照", code: "pjfs", color: "#05BB4C" },
- { name: "预测风速", name1: "预测光照", code: "ycfs", color: "#FF8300" },
- ],
- };
- },
- computed: {
- series() {
- let series = [];
- if (this.chartData && this.chartData.xAxis.length) {
- for (let key in this.chartData) {
- this.chartName.forEach((ele) => {
- if (ele.code == key) {
- if (ele.code.includes("fs")) {
- series.push({
- name: this.type == -1 ? ele.name : ele.name1,
- type: "line",
- symbol: "circle",
- showAllSymbol: true,
- yAxisIndex: 1,
- symbolSize: 0,
- smooth: true,
- lineStyle: {
- normal: {
- width: 1,
- color: ele.color,
- },
- // borderColor: "rgba(0,0,0,.4)",
- },
- itemStyle: {
- color: ele.color,
- },
- tooltip: {
- show: true,
- },
- data: this.chartData[key],
- });
- } else {
- series.push({
- name: this.type == -1 ? ele.name : ele.name1,
- type: "line",
- symbol: "circle",
- showAllSymbol: true,
- yAxisIndex: 0,
- symbolSize: 0,
- smooth: true,
- lineStyle: {
- normal: {
- width: 1,
- color: ele.color,
- },
- // borderColor: "rgba(0,0,0,.4)",
- },
- itemStyle: {
- color: ele.color,
- },
- tooltip: {
- show: true,
- },
- data: this.chartData[key],
- });
- }
- }
- });
- }
- }
- return series;
- },
- // lengend() {
- // let arr=[]
- // this.chartData.lengend.forEach((i) => {
- // if (this.chartName.some((item) => item.code == i)) {
- // i = item.name;
- // }
- // });
- // },
- },
- methods: {
- initChart() {
- let chart = echarts.init(this.$el);
- //图表配置
- var option = {
- color: this.color,
- tooltip: {
- trigger: "axis",
- },
- legend: {
- data: this.chartName.map((item) => {
- return {
- name: item.name,
- itemStyle: {
- color: item.color,
- },
- };
- }),
- itemHeight: 10,
- textStyle: {
- fontSize: 12,
- color: "#93989A",
- },
- top: "5%",
- right: "15%",
- },
- grid: {
- top: "22%",
- left: "4%",
- right: "4%",
- bottom: "12%",
- containLabel: true,
- },
- xAxis: {
- type: "category",
- boundaryGap: true,
- data: this.chartData?.xAxis || [],
- axisLabel: {
- textStyle: {
- color: "#93989A",
- },
- // formatter: function (params) {
- // return params.split(" ")[0] + "\n" + params.split(" ")[1];
- // },
- },
- splitLine: {
- show: false,
- },
- axisLine: {
- lineStyle: {
- color: "#93989A",
- },
- },
- },
- yAxis: [
- {
- name: "MW",
- type: "value",
- nameTextStyle: {
- color: "#93989A",
- },
- axisLabel: {
- formatter: "{value}",
- textStyle: {
- color: "#93989A",
- },
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: "rgba(96,103,105,0.3)",
- type: "dashed",
- },
- },
- },
- {
- name: this.type == -1 ? "m/s" : "W/m²",
- nameTextStyle: {
- color: "#93989A",
- },
- type: "value",
- axisLabel: {
- show: true,
- formatter: "{value}",
- textStyle: {
- color: "#93989A",
- },
- },
- splitLine: {
- show: false,
- },
- },
- ],
- series: this.series || [],
- };
- if (this.isDouble) {
- option.title = {
- text: this.chartData?.name,
- top: "5%",
- left: "35%",
- textStyle: {
- fontSize: 25,
- color: "rgba(255,255,255,0.8)",
- fontFamily: 'Arial, "SourceHanSans", "Microsoft YaHei", sans-serif',
- },
- };
- }
- chart.setOption(option);
- },
- },
- emits: {
- areaClick: null,
- },
- created() {
- this.id = "line-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();
- });
- },
- watch: {
- "$store.state.themeName"() {
- this.initChart();
- },
- },
- };
- </script>
- <style lang="less">
- .chart {
- width: 100%;
- height: 100%;
- // display: inline-block;
- }
- </style>
|