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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
| <template>
| <div class="bar-chart">
| <ChartTitle name="物料需求统计"></ChartTitle>
| <div class="bar-contents">
| <div class="chart" ref="chart"></div>
| </div>
| </div>
| </template>
|
| <script>
| import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
| //引入echart
| import * as echarts from "echarts";
| export default {
| components: {
| ChartTitle,
| },
| props: {},
| data() {
| return {
| chartData: {
| datax: [
| "产品1",
| "产品2",
| "产品3",
| "产品4",
| "产品5",
| "产品6",
| "产品7",
| "产品8",
| "产品9",
| "产品10",
| ],
| datay: [120, 200, 150, 380, 470, 150, 230, 130, 210, 145, 330],
| },
| };
| },
| mounted() {
| this.pieChart("chart", this.chartData);
| },
| watch: {},
| methods: {
| //在职
| pieChart(chartName, data) {
| let that = this;
| let chartDom = this.$refs[chartName];
| let myChart = echarts.init(chartDom);
| let option;
| let lineColor = "#35ddc74d";
| if (data) {
| option = {
| color: ["#00FFFF", "#dcb018"],
| tooltip: {
| trigger: "axis",
| axisPointer: {
| type: "none",
| },
| },
| grid: {
| right: "80px",
| bottom: "60px",
| left: "60px",
| top: "30px",
| },
| dataZoom: [
| {
| type: "inside",
| yAxisIndex: 0,
| show: false,
| startValue: 0, // 从头开始
| endValue: 5, // 一次性展示几个
| },
| ],
| legend: {
| itemWidth: 8,
| itemHeight: 8,
| itemGap: 35, //间距
| bottom: "5px",
| left: "center",
| },
| yAxis: [
| {
| type: "category",
| axisTick: {
| show: false,
| },
| axisLine: {
| show: true,
| lineStyle: {
| color: lineColor,
| },
| },
| axisLabel: {
| // rotate:45,
| margin: 10,
| show: true,
| textStyle: {
| color: function (params, index) {
| let colorList = ["#dcb018", "#00FFFF"];
| if (index % 2 == 0) {
| return colorList[0];
| } else {
| return colorList[1];
| }
| },
| },
| },
| data: data.datax ? data.datax : [],
| },
| ],
| xAxis: [
| {
| type: "value",
| name: "单位:件",
| // min: data.yAxis[0].min?data.yAxis.min:0,
| minInterval: 1, //坐标轴是整数
| max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5, //数据最大值加3
| interval:
| (Math.ceil(eval(`Math.max(${data.datay})`) / 7) * 7) / 7,
| position: "left",
| axisLine: {
| show: true,
| lineStyle: {
| color: "#0a112B",
| },
| },
| nameTextStyle: {
| color: "#00FFFF",
| },
| splitLine: {
| show: true,
| lineStyle: {
| // 使用深浅的间隔色
| color: lineColor,
| },
| },
| axisTick: {
| show: false,
| },
|
| axisLabel: {
| textStyle: {
| color: "#00FFFF",
| },
| },
| },
| ],
| series: [
| {
| type: "bar",
| name: "",
| barWidth: "15",
| itemStyle: {
| normal: {
| //柱形图圆角,初始化效果
| barBorderRadius: [4, 4, 0, 0],
| color: function (params) {
| let colorList = ["#dcb018", "#00FFFF"];
| if (params.dataIndex % 2 == 0) {
| return colorList[0];
| } else {
| return colorList[1];
| }
| },
| },
| },
| data: data.datay,
| },
| ],
| };
| setInterval(function () {
| // 每次向左滑动一个,最后一个从头开始。
| if (option.dataZoom[0].endValue == that.chartData.datay.length) {
| option.dataZoom[0].startValue = 0;
| option.dataZoom[0].endValue = 5;
| } else {
| option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1;
| option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1;
| }
| myChart.setOption(option);
| }, 4000);
|
| option && myChart.setOption(option);
| window.addEventListener("resize", function () {
| myChart.resize();
| });
| } else {
| option = {};
| myChart.setOption(option, true);
| }
| },
| },
| };
| </script>
|
| <style scoped lang="scss">
| .bar-chart {
| width: 100%;
| height: calc(100% - 20px);
| padding: 20px 0 0;
| .bar-contents {
| width: 100%;
| height: calc(100% - 60px);
| border: 1px solid #00ffff;
| box-sizing: border-box;
| .chart {
| width: 100%;
| height: 100%;
| }
| }
| }
| </style>
|
|