123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- <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 {
- props: {
-
- width: {
- type: String,
- default: "100%",
- },
-
- height: {
- type: String,
- default: "350px",
- },
-
- chartTitle: {
- type: String,
- default: "自定义图表组件",
- },
-
- xAxisData: {
- type: Array,
- default: () => {
- return [];
- },
- },
-
- yAxisData: {
- type: Array,
- default: () => {
- return [];
- },
- },
-
- seriesData: {
- type: Array,
- default: () => {
- return [];
- },
- },
-
- showLegend: {
- type: Boolean,
- default: true,
- },
-
- brushSelected: {
- type: Boolean,
- default: true,
- },
- },
- data() {
- return {
- id: "",
- chart: null,
- color: [
- "#05bb4c",
- "#4b55ae",
- "#fa8c16",
- "#f8de5b",
- "#1a93cf",
- "#c531c7",
- "#bd3338",
- ],
- };
- },
- methods: {
- resize() {},
- initChart() {
- const that = this;
- let myChart = echarts.init(document.getElementById(this.id));
-
- const option = {
-
- title: {
- text: that.chartTitle,
- textStyle: {
- fontSize: util.vh(16),
- color: that.$store.state.themeName === "dark" ? "#fff" : "#000",
- },
- },
- backgroundColor:
- that.$store.state.themeName === "dark"
- ? "rgba(0,0,0,0.4)"
- : "rgba(255,255,255,0.5)",
-
- toolbox: {
- show: true,
- x: "right",
- position: [10, 10],
- backgroundColor:
- that.$store.state.themeName === "dark"
- ? "rgba(0,0,0,0.4)"
- : "rgba(255,255,255,0.5)",
- borderColor:
- that.$store.state.themeName === "dark"
- ? partten.getColor("gray")
- : "#000",
- textStyle: {
- fontSize: util.vh(16),
- color: that.$store.state.themeName === "dark" ? "#fff" : "#000",
- },
- iconStyle: {
- borderColor:
- that.$store.state.themeName === "dark" ? "#fff" : "#000",
- },
- emphasis: {
- iconStyle: {
- borderColor:
- that.$store.state.themeName === "dark" ? "#fff" : "#000",
- },
- },
-
-
-
-
-
-
-
-
-
- },
- tooltip: {
- trigger: "item",
- axisPointer: {
- type: "cross",
- },
- backgroundColor:
- that.$store.state.themeName === "dark"
- ? "rgba(0,0,0,0.4)"
- : "rgba(255,255,255,0.5)",
- borderColor:
- that.$store.state.themeName === "dark"
- ? partten.getColor("gray")
- : "#000",
- textStyle: {
- fontSize: util.vh(16),
- color: that.$store.state.themeName === "dark" ? "#fff" : "#000",
- },
- formatter(params) {
- return params.name
- ? `${params.seriesName}<br />风速:${params.name}米/s<br />功率:${params.value}kW`
- : `${params.seriesName}<br />风速:${params.data[0]}米/s<br />功率:${params.data[1]}kW`;
- },
- },
- brush: {
-
-
- transformable: true,
- throttleType: "debounce",
- throttleDelay: 600,
- removeOnClick: false,
- brushType: "polygon",
- brushMode: "multiple",
- brushStyle: {
- borderWidth: 1,
- color: "rgba(255,36,36,0.2)",
- borderColor: "#ff2424",
- },
-
-
-
- },
- dataZoom: [
- {
- type: "inside",
- show: true,
- realtime: true,
- start: 0,
- end: 100,
- },
- {
- type: "slider",
- show: true,
- realtime: true,
- start: 0,
- end: 100,
- },
- ],
- textStyle: {
- fontSize: util.vh(16),
- color: that.$store.state.themeName === "dark" ? "#fff" : "#000",
- },
-
- legend: {
- show: that.showLegend,
- data: ["风速功率", "实际功率", "最优功率"],
- right: "120",
- top: "5",
- icon: "circle",
- itemWidth: 6,
- inactiveColor:
- that.$store.state.themeName === "dark"
- ? partten.getColor("gray")
- : "#000",
- textStyle: {
- color:
- that.$store.state.themeName === "dark"
- ? partten.getColor("grayl")
- : "#000",
- fontSize: 12,
- },
- },
- grid: {
- top: 32,
- left: 40,
- right: 40,
- bottom: 24,
- },
-
- xAxis: [
- {
- type: "category",
- boundaryGap: false,
- data: that.xAxisData || [
- "0",
- "1",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9",
- "10",
- "11",
- "12",
- "13",
- "14",
- "15",
- "16",
- "17",
- "18",
- "19",
- "20",
- "21",
- "22",
- "23",
- "24",
- "25",
- ],
- min: 0,
- axisLabel: {
- formatter: "{value}",
- fontSize: util.vh(14),
- },
- textStyle: {
- color:
- this.$store.state.themeName === "dark"
- ? partten.getColor("gray")
- : "#000",
- },
- },
- {
-
- show: false,
- type: "value",
- boundaryGap: false,
-
- min: 0,
- max: that?.xAxisData[that?.xAxisData?.length - 1],
- scale: true,
- axisLabel: {
- formatter: "{value}",
- },
- splitLine: {
- show: false,
- },
- },
- ],
-
- yAxis: {
- splitLine: { show: false },
- },
-
- series: that.seriesData,
- };
- that.resize = function () {
- myChart.resize();
- };
- window.addEventListener("resize", that.resize);
- myChart.setOption(option);
- if (that.brushSelected) {
- myChart.off("brushSelected");
- myChart.on("brushSelected", (params) => {
- that.$emit("getSelected", params.batch || []);
- });
- myChart.dispatchAction({
- type: "takeGlobalCursor",
-
- key: "brush",
- brushOption: {
-
- brushType: "polygon",
-
- brushMode: "multiple",
- },
- });
- }
- },
- },
- created() {
- this.id = "chart-" + util.newGUID();
- },
- mounted() {
- this.$nextTick(() => {
- this.$el.style.width = this.width;
- this.$el.style.height = this.height;
- this.initChart();
- });
- },
- updated() {
- let myChart = echarts.init(document.getElementById(this.id));
- myChart.dispose();
- this.$nextTick(() => {
- this.initChart();
- });
- },
- unmounted() {
- window.removeEventListener("resize", this.resize);
- },
- };
- </script>
- <style lang="scss">
- .chart {
- width: 100%;
- height: 100%;
- display: inline-block;
- }
- </style>
|