123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- <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: {
- width: {
- type: String,
- default: "100%",
- },
- height: {
- type: String,
- default: "50px",
- },
- title: {
- type: String,
- default: "风机",
- },
- // 传入数据
- data: {
- type: Array,
- default: () => {
- return [
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 1,
- 0,
- 0,
- 0,
- 0,
- 0,
- 1,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 1,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- ];
- },
- },
- // 单位
- color: {
- type: String,
- default: "green",
- },
- lineTitle:{
- type: Array,
- default: () => [],
- }
- },
- data() {
- return {
- id: "",
- chart: null,
- // 时间轴
- xData: [
- "00:00",
- "00:15",
- "00:30",
- "00:45",
- "01:00",
- "01:15",
- "01:30",
- "01:45",
- "02:00",
- "02:15",
- "02:30",
- "02:45",
- "03:00",
- "03:15",
- "03:30",
- "03:45",
- "04:00",
- "04:15",
- "04:30",
- "04:45",
- "05:00",
- "05:15",
- "05:30",
- "05:45",
- "06:00",
- "06:15",
- "06:30",
- "06:45",
- "07:00",
- "07:15",
- "07:30",
- "07:45",
- "08:00",
- "08:15",
- "08:30",
- "08:45",
- "09:00",
- "09:15",
- "09:30",
- "09:45",
- "10:00",
- "10:15",
- "10:30",
- "10:45",
- "11:00",
- "11:15",
- "11:30",
- "11:45",
- "12:00",
- "12:15",
- "12:30",
- "12:45",
- "13:00",
- "13:15",
- "13:30",
- "13:45",
- "14:00",
- "14:15",
- "14:30",
- "14:45",
- "15:00",
- "15:15",
- "15:30",
- "15:45",
- "16:00",
- "16:15",
- "16:30",
- "16:45",
- "17:00",
- "17:15",
- "17:30",
- "17:45",
- "18:00",
- "18:15",
- "18:30",
- "18:45",
- "19:00",
- "19:15",
- "19:30",
- "19:45",
- "20:00",
- "20:15",
- "20:30",
- "20:45",
- "21:00",
- "21:15",
- "21:30",
- "21:45",
- "22:00",
- "22:15",
- "22:30",
- "22:45",
- "23:00",
- "23:15",
- "23:30",
- "23:45",
- ],
- };
- },
- computed: {
- colorValue() {
- return partten.getColor(this.color);
- },
- },
- methods: {
- resize() {},
- initChart() {
- const chart = echarts.init(this.$el);
- let option = {
- title: {
- text: this.title,
- textStyle: {
- color: "#ffffffcc",
- fontSize: 14,
- },
- left: 16,
- top: 0,
- },
- tooltip: {
- trigger: "axis",
- backgroundColor: "rgba(0,0,0,0.4)",
- borderColor: partten.getColor("gray"),
- textStyle: {
- color: "#fff",
- fontSize: util.vh(16),
- },
- },
- grid: {
- top: 40,
- left: 16,
- right: 16,
- bottom: 32,
- },
- xAxis: [
- {
- type: "category",
- data: this.xData,
- axisLine: {
- show: false,
- lineStyle: {
- color: partten.getColor("gray"),
- },
- },
- axisLabel: {
- show: true,
- margin: 16,
- interval: 7,
- },
- axisTick: {
- show: false,
- lineStyle: {
- color: partten.getColor("gray"),
- },
- },
- },
- ],
- yAxis: [
- {
- type: "value",
- splitNumber: 1,
- min: 0,
- max: 1,
- axisLine: {
- show: false,
- },
- axisLabel: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- lineStyle: {
- color: partten.getColor("gray"),
- },
- },
- },
- ],
- series: [
- {
- type: "line",
- data: this.data,
- showAllSymbol: true,
- symbol: "circle",
- symbolSize: 10,
- lineStyle: {
- normal: {
- color: this.colorValue,
- width: 1,
- },
- },
- label: {
- show: false,
- },
- itemStyle: {
- color: this.colorValue,
- shadowColor: this.colorValue,
- shadowBlur: 4,
- },
- },
- ],
- };
- chart.clear();
- chart.setOption(option);
- this.resize = function() {
- chart.resize();
- };
- window.addEventListener("resize", this.resize);
- },
- },
- created() {
- this.xData = this.lineTitle;
- this.$nextTick(()=>{
- this.id = "pie-chart-" + util.newGUID();
- });
- },
- mounted() {
- this.xData = this.lineTitle;
- this.$nextTick(() => {
- this.$el.style.width = this.width;
- this.$el.style.height = this.height;
- this.initChart();
- });
- },
- updated() {
- this.xData = this.lineTitle;
- this.$nextTick(() => {
- this.initChart();
- });
- },
- unmounted() {
- window.removeEventListener("resize", this.resize);
- },
- };
- </script>
- <style lang="less">
- .chart {
- width: 100%;
- height: 100%;
- display: inline-block;
- }
- </style>
|