123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <template>
- <div class="chart" :id="id"></div>
- </template>
- <script>
- import * as echarts from "echarts";
- export default {
- name: "multiple-line-chart",
- componentName: "multiple-line-chart",
- watch: {
- 'list': {
- deep: true,
- handler: function (json) {
- this.initChart()
- }
- }
- },
- props: {
- width: {
- type: String,
- default: "100%",
- },
- height: {
- type: String,
- default: "13.889vh",
- },
-
- list: {
- type: Array,
- default: () => [
- {
- title: "有功设定限值(MW)",
- yAxisIndex: 0,
- value: [],
- },
- {
- title: "实发有功(MW)",
- yAxisIndex: 0,
- value: [],
- },
- ],
- },
- colors: {
- type: Array,
- default: () => ["rgba(75, 85, 174, 1)", "rgba(05, 187, 76, 1)"]
- },
-
- units: {
- type: Array,
- default: () => ["(MW)", "(风速)"],
- },
- showLegend: {
- type: Boolean,
- default: false,
- },
- hoverType: {
- type: String,
- default: "item",
- },
- },
- data() {
- return {
- id: "",
- chart: null,
-
- };
- },
- computed: {
- datas() {
- return this.list.map((t) => {
- return t.value;
- });
- },
- legend() {
- return this.list.map((t) => {
- return t.title;
- });
- },
- xdata() {
- if (this.list.length > 0)
- return this.list[0].value.map((t) => {
- return t.text;
- });
- return [];
- },
- series() {
- let result = [];
- this.list.forEach((value, index) => {
- result.push({
- name: value.title,
- type: "line",
- smooth: true,
- showSymbol: false,
- zlevel: index,
- lineStyle: {
- normal: {
- color: this.colors[index],
- width: 1,
- },
- },
- itemStyle: {
- normal: {
- color: this.colors[index],
- },
- },
- tooltip: {
- show: true,
- position: [10, 10],
- },
- yAxisIndex: value.yAxisIndex,
- data: value.value.map((t) => {
- return t.value;
- }),
- });
- });
- return result;
- },
- yAxis() {
- let result = [];
- this.units.forEach((value, index) => {
- result.push({
- type: "value",
- name: value,
- axisLabel: {
- formatter: "{value}",
- fontSize: 14,
- },
- axisLine: {
- show: false,
- },
-
- splitLine: {
- show: index == 0,
- lineStyle: {
- color: '#606769',
- type: "dashed",
- },
- },
- });
- });
- return result;
- },
- },
- methods: {
- hexToRgba(hex, opacity) {
- let rgbaColor = "";
- let reg = /^#[\da-f]{6}$/i;
- if (reg.test(hex)) {
- rgbaColor = `rgba(${parseInt("0x" + hex.slice(1, 3))},${parseInt("0x" + hex.slice(3, 5))},${parseInt("0x" + hex.slice(5, 7))},${opacity})`;
- }
- return rgbaColor;
- },
- resize() { },
- initChart() {
- let chart = echarts.init(this.$el);
- let option = {
- color: this.colors,
- tooltip: {
- trigger: this.hoverType,
- axisPointer:
- this.hoverType != "item"
- ? {
- type: "cross",
- }
- : {},
- backgroundColor: "rgba(0,0,0,0.4)",
- borderColor: '#606769',
- textStyle: {
- fontSize: 16,
- color: "#4B55AE",
- },
- },
- legend: {
- show: this.showLegend,
- data: this.legend,
- right: 56,
- icon: "circle",
- itemWidth: 6,
- inactiveColor: '#606769',
- textStyle: {
- color: '#B3BDC0',
- fontSize: 12,
- },
- },
- grid: {
- top: 32,
- left: 40,
- right: 40,
- bottom: 24,
- },
- xAxis: [
- {
- type: "category",
- boundaryGap: false,
- axisLabel: {
- interval: 60,
- showMinLabel: true,
- showMaxLabel: true,
- formatter: "{value}",
- fontSize: 14,
- textStyle: {
- color: '#606769',
- },
- },
- axisLine: {
- show: false,
- },
- data: this.xdata,
- },
- ],
- yAxis: this.yAxis,
- series: this.series,
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- };
- chart.clear();
- chart && option && chart.setOption(option);
- this.resize = function () {
- chart.resize();
- };
- window.addEventListener("resize", this.resize);
- chart.resize();
- },
- },
- created() {
- this.$nextTick(() => {
- this.id = "pie-chart-photo";
- });
- },
- 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>
|