123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- <template>
- <div class="chart" :id="id"></div>
- </template>
- <script>
- import util from "@tools/util";
- import partten from "@tools/partten";
- import * as echarts from "echarts";
- import chartTheme from './current-scatter-chart.json'
- export default {
- name: 'currentScatterChart',
- 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 [];
- },
- },
- dataSet: {
- type: String,
- default: ''
- },
-
- seriesData: {
- type: Array,
- default: () => {
- return [];
- },
- },
- maxMinData: {
- type: Array,
- default: () => {
- return [];
- },
- },
-
- showLegend: {
- type: Boolean,
- default: true,
- },
-
- brushSelected: {
- type: Boolean,
- default: false,
- },
- theme: {
- type: Boolean,
- default: false,
- },
- echartsTheme: {
- type: String,
- default: '',
- },
- },
- data() {
- return {
- id: "",
- chart: null,
- color: [
- "#05bb4c",
- "#4b55ae",
- "#fa8c16",
- "#f8de5b",
- "#1a93cf",
- "#c531c7",
- "#bd3338",
- ],
- };
- },
- computed: {
- collapse() {
- return this.$store.state.collapse
- }
- },
- watch: {
- height() {
- if (this.chart) {
- this.chart.resize()
- }
- },
- collapse(val) {
- if (this.chart) {
- setTimeout(() => {
- this.chart.resize()
- }, 300)
- }
- },
- },
- methods: {
- resize() {},
- initChart() {
- const that = this;
- echarts.registerTheme('chartTheme', chartTheme)
- let myChart = echarts.init(document.getElementById(this.id), that.echartsTheme);
- document.getElementById(that.id).removeAttribute("_echarts_instance_") ? document.getElementById(
- that.id)
- .removeAttribute("_echarts_instance_") : ''
- that.chart = myChart
-
- let option = {
-
- title: {
- text: that.chartTitle,
- right: 440,
- top: 4,
- textStyle: {
- fontSize: 14,
- color: that.echartsTheme === "dark" ? partten.getColor("grayl") : "#000",
- },
- },
-
-
-
-
-
- color: [
- "#3D54BE",
- "rgb(255,0,0)",
- "#a1a1a1",
- "#0098d9",
- "#FF8700",
- "#005eaa",
- "#cda819",
- "#32a487"
- ],
- toolbox: {
- show: true,
- x: "right",
- position: [10, 10],
-
- borderColor: partten.getColor("gray"),
- textStyle: {
- fontSize: util.vh(16),
- color: partten.getColor("gray")
- },
- iconStyle: {
- borderColor: partten.getColor("gray")
- },
- emphasis: {
- iconStyle: {
- borderColor: partten.getColor("gray")
- },
- },
- },
- tooltip: {
- trigger: "item",
- axisPointer: {
- type: "cross",
- },
- backgroundColor: "rgba(0,0,0,0.4)",
- borderColor: partten.getColor("gray"),
- textStyle: {
- fontSize: util.vh(16),
- color: "#fff",
- },
- formatter(params) {
- return params.value.length ?
- `${params.seriesName}<br />风速:${params.value[0]} m/s<br />功率:${params.value[1]} kW<br />温度:${params.value[2]} ℃` :
- `${params.name}`;
- },
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- dataZoom: [{
- type: "inside",
- show: false,
- realtime: true,
- start: 0,
- end: 100,
- },
- {
- type: "slider",
- show: false,
- realtime: true,
- start: 0,
- end: 100,
- },
- ],
- textStyle: {
- fontSize: util.vh(16),
- color: that.echartsTheme === "dark" ? "#fff" : "#000",
- },
-
- legend: {
- show: that.showLegend,
- data: ["拟合功率", "保证功率", "无用点", "有用点", "Cp值"],
- right: "120",
- top: "5",
-
- itemWidth: 6,
- inactiveColor: that.echartsTheme === "dark" ?
- partten.getColor("gray") : "#838383",
- textStyle: {
- color: that.echartsTheme === "dark" ?
- partten.getColor("grayl") : "#838383",
- fontSize: 12,
- },
- },
- visualMap: [{
- type: 'continuous',
- min: that.maxMinData[1],
- max: that.maxMinData[0],
- dimension: 2,
- orient: 'vertical',
- right: 4,
- top: 50,
- itemHeight: 600,
-
- text: [that.maxMinData[0], that.maxMinData[1]],
- calculable: false,
- range: [that.maxMinData[1], that.maxMinData[0]],
- inRange: {
- color: ['#000', 'rgb(75,11,106)', 'rgb(133,33,106)', 'rgb(176,49,92)',
- 'rgb(210,70,69)', 'rgb(235,100,42)', 'rgb(247,126,21)',
- 'rgb(252,183,28)', 'rgb(249,252,156)'
- ]
- },
- outOfRange: {
- color: ['#eee', '#eee']
- }
- }],
- grid: {
- top: 48,
- left: 40,
- right: 40,
- bottom: 24,
- },
-
- xAxis: [{
- name: 'm/s',
- nameTextStyle: {
- color: '#838383'
- },
- type: "value",
- boundaryGap: false,
- data: that.xAxisData || [],
- min: 0,
- max: 25,
- interval: 1,
- axisLabel: {
- formatter: "{value}",
- },
- splitLine: {
- show: false,
- },
- textStyle: {
- color: that.echartsTheme === "dark" ?
- partten.getColor("gray") : "#000",
- },
- }, ],
-
- yAxis: [{
- splitLine: {
- show: false
- },
- position: 'left',
- min: 0,
- name: 'kW',
- nameTextStyle: {
- color: '#838383'
- }
- }, {
- splitLine: {
- show: false
- },
- position: 'right',
- min: 0,
- }],
- animation: true,
- dataset: that.dataSet.length ? JSON.parse(that.dataSet) : [],
-
- series: that.seriesData,
- };
- if (!that.theme) {
- option.backgroundColor = ''
- }
- that.resize = function () {
- myChart.resize();
- };
- window.addEventListener("resize", that.resize);
- myChart.setOption(option);
- if (that.brushSelected) {
- myChart.dispatchAction({
- type: "takeGlobalCursor",
-
- key: "brush",
- brushOption: {
- seriesIndex: [2, 3],
- yAxisIndex: 0,
- transformable: true,
- throttleType: "debounce",
- throttleDelay: 1000,
- removeOnClick: true,
- brushType: "polygon",
- brushMode: "multiple",
- brushStyle: {
- borderWidth: 1,
- color: "rgba(255,36,36,0.2)",
- borderColor: "#ff2424",
- },
- },
- });
- }
- myChart.off("brushSelected");
- myChart.on("brushSelected", (params) => {
- that.$emit("getSelected", params.batch || []);
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- },
- 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), this.echartsTheme);
- myChart.dispose();
- this.$nextTick(() => {
- this.initChart();
- });
- },
- unmounted() {
- window.removeEventListener("resize", this.resize);
- },
- };
- </script>
- <style lang="less">
- .chart {
- width: 100%;
- height: 100%;
- display: inline-block;
- }
- </style>
|