# 前言

# ✨魁首

🔔一个没有天赋的前端程序员👨‍💻 💡博客

# 🔰关注我

🤖Github |🔑CSDN | 💎掘金 | 📖 知乎 | 💡博客 |

# 一、elementUI tabs切换 echarts宽度变成100px,怎么让多个Echarts图表宽度随着窗口自动适应?

原因:echarts绘制图表计算宽度的时候,由于第二个tab的属性display: none;所以无法获取到clientWidth,而 parseInt(stl.width, 10)) 将width: 100%;转为100,所以计算出的图表宽度为100px。

解决

<template>
    <el-tabs type="border-card"  ref="chartWrap" :tab-position="tabPosition" @tab-click="handleClick" class="m-el-tabs">
      <el-tab-pane label="图表1">
        <el-row v-loading="chartLoading" style="width: 100%;" >
          <v-chart :options="size" ref="size" class="indexChart"/>
        </el-row>
      </el-tab-pane>
      <el-tab-pane label="图表2">
        <el-row v-loading="chartLoading" style="width: 100%;" >
          <v-chart :options="btop" ref="btop" class="indexChart" />
        </el-row>
      </el-tab-pane>
      <el-tab-pane label="图表3">
        <el-row v-loading="chartLoading" style="width: 100%;" >
          <v-chart :options="growth" ref="growth" class="indexChart"/>
        </el-row>
      </el-tab-pane>
      </el-tab-pane>
    </el-tabs>
</template>
<script>
    import echarts from "echarts"; //引入echarts
    import elementResizeDetectorMaker from "element-resize-detector"; // 引入elements封装的自适应工具
    export default {
        data(){
            tabPosition: 'left',
            size: null,
            btop: null,
            growth: null,
        },
        methods:{
            formatOption(){
                this.size = {}, // echarts在这绘制
                this.btop = {},
                this.growth = {}
            },
            // ECharts图自适应屏幕变化
            handleClick(){
              const erd = elementResizeDetectorMaker();
              erd.listenTo((this.$refs.chartWrap).$el,()=>{
                this.$refs.size.resize(); // 初始化首张图
                this.$nextTick(()=>{ this.$refs.size.resize() }); // 图1
                this.$nextTick(()=>{ this.$refs.btop.resize() }); // 图2
                this.$nextTick(()=>{ this.$refs.growth.resize() });// 图3
              })
        },
        mounted(){ // 初始化一下
          this.handleClick()
        }
    }
</script>
<style>
    .indexChart{
      width: 100%;
    }
</style>
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

参考:https://www.cnblogs.com/hanhanours/p/11977863.html https://www.cnblogs.com/zhaohongcheng/p/12918478.html https://blog.csdn.net/zhangshab/article/details/81364943

# 二、Jquery +Ajax 请求Json文件,绘制Echarts 上下两个堆叠折线图

Echarts上下两个堆叠折线图.gif

HTML部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Echarts 上下两个堆叠折线图的实现</title>
</head>
<body>
    <div id="rateTable" style="height: 100%; width: 100%;min-height: 470px"></div>
</body>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js"></script>
<script>
    <!--Echarts在这里绘制-->
</script>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

json数据格式

[
  {
    "dt": "2020-01-02",        //x轴日期
    "portfolio_net_value": 0.0,//数据1
    "SH_net_value": 0.0,       //数据2
    "alpha_net_value": 0.0,    //数据3
    "cur_drawdown_rate": 0.0   //数据4
  },
  {
    "dt": "2020-01-03",
    "portfolio_net_value": -0.0083730541368796,
    "SH_net_value": 0.0008564679888114,
    "alpha_net_value": -0.0092295221256908,
    "cur_drawdown_rate": -0.0083730541368796
  },
  {
    "dt": "2020-01-06",
    "portfolio_net_value": -0.0040413555084052,
    "SH_net_value": 0.0109406884571092,
    "alpha_net_value": -0.0148841629410285,
    "cur_drawdown_rate": -0.0040413555084056
  },
  {
    "dt": "2020-01-07",
    "portfolio_net_value": 0.0088552022531673,
    "SH_net_value": 0.0230293795826546,
    "alpha_net_value": -0.0139078885557082,
    "cur_drawdown_rate": 0.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
26
27
28
29
30
31

js部分

<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js"></script>
<script>
    var mychartdd = echarts.init(document.getElementById('rateTable'));
    var seriesName1 = '数据1';
    var seriesName2 = '数据2';
    var seriesName3 = '数据3';
    var seriesName4 = '数据4';
    var option = {
        legend: { // 图例
            data: [seriesName1, seriesName2, seriesName3, seriesName4],
            right: '10%',
        },
        dataZoom: [ // 底部红色数据框拖动条
            {
                id: 'datazoomX',
                type: 'slider',
                xAxisIndex: [0, 1],
                height: 20,
                top: '69%',
                right: 10,
                left: 10,
                handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
                handleSize: '80%',
                fillerColor: "rgba(255, 76, 31,.2)",
                dataBackground: {
                    areaStyle: {
                        color: ''
                    },
                    lineStyle: {
                        opacity: 1,
                        color: '#FF4C1F'
                    }
                },
                handleStyle: {
                    color: '#FF4C1F',
                },
                filterMode: 'weakFilter',
                zoomOnMouseWheel: 'false'
            },{
                id: 'dataZoomY',
                type: 'inside',
                xAxisIndex: [0, 1],
                filterMode: 'weakFilter',
                zoomOnMouseWheel: 'false'
            }
        ],
        tooltip: { // 鼠标悬停提示框组件
            trigger: 'axis',
            axisPointer: {
                type: 'cross', //十字准星指示器
            },
            formatter: function (datas) { //提示框浮层内容格式 
                var res = datas[0].name + '<br/>';
                var length = datas.length;
                var i = 0;
                for (; i < length; i++) {
                    res += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' + datas[i].color + ';"></span>' + datas[i].seriesName + ':' + datas[i].value.toFixed(2) + '%' + '<br/>'
                }
                return res
            }
        },
        axisPointer: { // 坐标轴指示器
            link: {xAxisIndex: 'all'},
            label: {
                backgroundColor: '#777'
            }
        },
        grid: [ //直角坐标系内绘图网格
            {
                top: 20,
                left: 10,
                right: 0,
                bottom: 20,
                height: '60%',
            }, {
                left: 10,
                right: 0,
                bottom: 15,
                height: '20%',
            }
        ],
        xAxis:[
            {
                type: 'category',
                data: [],
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: '#D8D8D8'
                    }
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show:true,
                    textStyle: {
                        fontSize: 10,
                        color: '#222831'
                    },

                },
                splitLine: {
                    show: false
                },
                scale: true,
            },
            {
                type: 'category',
                gridIndex: 1,
                data: [],
                axisLine: {
                    lineStyle: {
                        color: "#D8D8D8"
                    }
                },
                scale: true,
                axisTick: {show: false},
                splitLine: {show: false},
                axisLabel: {show: false},

            }
        ],
        yAxis: [
            {
                scale: true,
                splitArea: {
                    show: false
                },
                splitNumber: 4,
                // max: 150,
                // logBase:10,
                axisLabel: {
                    show: true,
                    textStyle: {
                        fontSize: 10,
                        color: '#808080',
                        align: 'left'
                    },
                    formatter: '{value} %'
                },
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: '#D8D8D8'
                    }
                },
                axisTick: {
                    show: false
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: '#F5F5F5'
                    }
                },
                offset: -10,
            },
            {
                type: 'value',
                gridIndex: 1,
                offset: -10,
                axisLabel: {
                    show: true,
                    textStyle: {fontSize: 10, color: "#808080", align: 'left'},
                    formatter: '{value} %',
                },
                axisLine: {show: false},
                axisTick: {show: false},
                splitLine: {show: false}
            }
        ],
        series: [
            {
                name: seriesName1,
                type: 'line',
                data: [],
                color: "#FF7855",
                xAxisIndex: 0,
                yAxisIndex: 0,
                symbol: 'none',
            },
            {
                name: seriesName2,
                type: 'line',
                data: [],
                color: "#009DFF",
                xAxisIndex: 0,
                yAxisIndex: 0,
                symbol: 'none'
            },
            {
                name: seriesName3,
                type: 'line',
                data: [],
                color: "#FFBD00",
                xAxisIndex: 0,
                yAxisIndex: 0,
                symbol:'none',
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        {
                            offset: 0,
                            color: 'rgba(255, 189, 0, .5)'
                        },
                        {
                            offset: 1,
                            color: 'rgba(255, 189, 0, 0)'
                        }
                    ])
                },
            },
            {
                name: seriesName4,
                type: 'line',
                data: [],
                color: '#769CFA',
                gridIndex: 1,
                xAxisIndex: 1, //使用的 x 轴的 index,在单个图表实例中存在多个 x 轴的时候有用
                yAxisIndex: 1,
                symbol: 'none',
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: 'rgba(115,156,250,0.05)'
                    }, {
                        offset: 0.76,
                        color: 'rgba(115,156,250,0.25)'
                    }])
                },
            }
        ]
    };

    mychartdd.setOption(option);

    /*请求json数据*/
    $(function(){
        var SoilTemp1 = [], SoilTemp2 = [], SoilTemp3 = [], SoilTemp4 = [];// Y坐标值:各项指标数据
        var TM = [];// x坐标值:时间
        mychartdd.showLoading({ text: "图表数据正在加载中.....如果加载不出来,建议使用WebStorm工具打开" });
        $.ajax({
            type: "GET",
            // 请求地址
            url: "json/html1.json",
            // async:true,    //是否异步
            // dataType: "jsonp",  //预期的服务器响应的数据类型。
            // jsonp: "callback",  //在一个 jsonp 中重写回调函数的字符串。
            // xhrFields: {withCredentials: true},
            success: function (ret) {
                var date = ret;
                if (date == null) {
                    mychartdd.showLoading({ text: "未获取到数据,请选择正确的时间..." });
                }
                // 遍历上面 '数据1','数据2','数据3'
                for (var i = 0; i < date.length; i++) {
                    TM.push(date[i].dt); //时间
                    SoilTemp1.push(date[i].portfolio_net_value); //数据1
                    SoilTemp2.push(date[i].SH_net_value); //数据2
                    SoilTemp3.push(date[i].alpha_net_value); //数据3
                }
                // 遍历下面 ‘数据4’ 数据
                for (var j = 0; j < date.length; j++) {
                    SoilTemp4.push(date[j].cur_drawdown_rate); //数据4
                }
                mychartdd.hideLoading();    //隐藏加载动画
                mychartdd.setOption({       //加载数据图表
                    tooltip: [
                        {
                            trigger: 'axis'
                        },
                    ],
                    toolbox: { // 工具栏
                        show: false,
                        feature: {
                            saveAsImage: { show: false }, // 保存为图片
                            restore: { show: false },
                        },
                    },
                    calculable: true,
                    xAxis: [
                        {
                            type: 'category',
                            boundaryGap: false,
                            data: TM
                        },
                        {
                            type: 'category',
                            boundaryGap: false,
                            data: TM
                        },
                    ],
                    yAxis: [{},{}],//注意一定不能丢了这个,不然图表Y轴不显示
                    series: [
                        {
                            name: seriesName1,
                            type: 'line',
                            data: SoilTemp1
                        },
                        {
                            name: seriesName2,
                            type: 'line',
                            data: SoilTemp2
                        },
                        {
                            name: seriesName3,
                            type: 'line',
                            data: SoilTemp3
                        },
                        {
                            name: seriesName4,
                            type: 'line',
                            data: SoilTemp4
                        }
                    ]
                });
            }
        });
    });
</script>
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

看完感觉对你有帮助,记得关注 !

# 三、echarst 折线图下载csv曲线数据 功能的实现

业务场景:在echarts折线图中,右上角有个下载功能,但下载的内容是一张图片,能不能适当修改这个功能,让它下载的整条折线图的数据并导出csv格式的文件呢?安排!

需求分析:首先不能再使用Echarts官方提供的标签,用i标签的click事件触发json格式整理,最终导出为csv文件!

官方示例

image.png

html部分:

<div id="demo">
      <!-- 下载 -->
      <div style="float: right;">
        <i style="cursor: pointer;" class="el-icon-download" @click="handleDownload" />
      </div>
      <!-- 折线图 -->
      <div style="height: 496px; border: 1px solid #ebeef5;">
        <v-chart id="performanceChart" :options="performanceOption" style="width: 100%; height: 100%;" />
      </div>
</div>
1
2
3
4
5
6
7
8
9
10

js部分

import ECharts from "vue-echarts";
export default {
    components: {
        "v-chart": ECharts
    },
    data: {
          performanceOption: null, // 净值曲线的option
          fundPerformanceData: [
            {
              name: "日期",
              type: "date",
              id: null,
              data: [
                2022-02-28,
                2022-03-01,
                2022-03-02,
                2022-03-03,
                2022-03-04,
                2022-03-07,
                2022-03-08,
                2022-03-09,
                2022-03-10,
                2022-03-11,
                2022-03-14,
                2022-03-15,
                2022-03-16,
                2022-03-17,
                2022-03-18,
                2022-03-21,
                2022-03-22,
                2022-03-23,
                2022-03-24,
                2022-03-25,
                2022-03-28,
                2022-03-29,
                2022-03-30,
                2022-03-31,
                2022-04-01,
                2022-04-06
              ]
            },
            {
              name: "数据1",
              type: "fund",
              id: "SSP312",
              data: [
                1,
                1.0072107,
                1.006510235,
                1.000730169,
                0.990743452,
                0.97094713,
                0.940424825,
                0.926913562,
                0.948911381,
                0.956444466,
                0.929787421,
                0.886528866,
                0.919513112,
                0.941216068,
                0.950418761,
                0.965495909,
                0.964183414,
                0.969470427,
                0.964321415,
                0.954335972,
                0.951709649,
                0.942736322,
                0.959222206,
                0.950557456,
                0.948558405,
                0.948476298
              ]
            },
            {
              name: "数据2",
              type: "fund_account",
              id: "28100006868",
              data: [
                1,
                1.0072107,
                1.006510235,
                1.000730169,
                0.990743452,
                0.97094713,
                0.940424825,
                0.926913562,
                0.948911381,
                0.956444466,
                0.929787421,
                0.886528866,
                0.919513112,
                0.941216068,
                0.950418761,
                0.965495909,
                0.964183414,
                0.969470427,
                0.964321415,
                0.954335972,
                0.951709649,
                0.942736322,
                0.959222206,
                0.950557456,
                0.948558405,
                0.948476298
              ]
            },
            {
              name: "数据3",
              type: "fund_account|simulation",
              id: "28100006868",
              data: [
                1,
                1.00712249,
                1.007306985,
                1.00313626,
                0.993969641,
                0.975005943,
                0.941590608,
                0.925349535,
                0.948433073,
                0.956514871,
                0.928983025,
                0.880746789,
                0.912900696,
                0.937216573,
                0.947011817,
                0.96118454,
                0.960357662,
                0.968720774,
                0.96031809,
                0.952355055,
                0.950769517,
                0.936477151,
                0.95625449,
                0.951077739,
                0.947358103,
                0.954694728,
              ]
            },
            {
              name: "数据4",
              type: "fund|draw_down",
              id: "SSP312",
              data: [
                0,
                0,
                -0.00069545,
                -0.006434136,
                -0.016349357,
                -0.036003956,
                -0.06630775,
                -0.079722284,
                -0.05788195,
                -0.050402795,
                -0.076869,
                -0.119817863,
                -0.087069754,
                -0.065522172,
                -0.056385361,
                -0.041416151,
                -0.04271925,
                -0.037470087,
                -0.042582238,
                -0.052496193,
                -0.055103714,
                -0.064012801,
                -0.04764494,
                -0.056247659,
                -0.058232398,
                -0.058313918,
              ]
            }
          ]
        },
        methods: {
          formatPerformanceOption() {
            let fundData = []; // 数据1
            const fund_account = []; // 数据2
            const simulation = []; // 数据3
            let retracementData = []; // 数据4
            const legends = []; // 图例
            const dts = []; // X轴 时间
            const colors = [
              "#73DEB3",
              "#01BCFF",
              "#FFB701",
              "#A0A7E6",
              "#EEDD78",
              "#22C3AA",
              "#FAA9E1",
              "#95F0FE",
              "#FFC18E",
              "#92B7E2",
              "#6EA7A7",
              "#516B91",
              "#9AAA9C"
            ];
			//下面是数据分类展示过程,可忽略
            if (this.fundPerformanceData.length > 0) {
              this.fundPerformanceData.forEach((item) => {
                if (item.type !== "date" && item.type !== "fund|draw_down" && item.type !== "fund|max_draw_down") {
                  legends.push({ name: item.name });
                  if (!this.showExcess) {
                    for (let i = 0; i < item.data.length; i++) {
                      if (item.data[i] !== null)
                        item.data[i] = item.data[i] + 1;
                    }
                  }
                }
                if (item.type === "date") {
                  item.data.forEach((item) => {
                    dts.push(item.replaceAll("-", "/"));
                  });
                } else if (item.type === "fund_account") {
                  // 数据2 添加双向绑定key
                  this.$set(
                    this.selectedLegend,
                    item.name,
                    typeof this.selectedLegend[item.name] === "boolean"
                      ? this.selectedLegend[item.name]
                      : true
                  );
                  fund_account.push({
                    id: item.id,
                    name: item.name,
                    type: "line",
                    color: colors[fund_account.length % 3],
                    data: item.data,
                    date: dts,
                    xAxisIndex: 0,
                    symbol: false,
                    symbolSize: 0 // 拐点圆的大小
                  });
                } else if (item.type === "fund_account|simulation") {
                  // 数据3 添加双向绑定key
                  this.$set(
                    this.selectedLegend,
                    item.name,
                    typeof this.selectedLegend[item.name] === "boolean"
                      ? this.selectedLegend[item.name]
                      : false
                  );
                  simulation.push({
                    name: item.name,
                    type: "line",
                    color: colors[simulation.length % 3],
                    data: item.data,
                    symbolSize: 0, // 拐点圆的大小
                    itemStyle: {
                      // 折线图虚线样式
                      normal: {
                        lineStyle: {
                          width: 2, // 线宽
                          type: "dotted" // 'dotted'虚线 'solid'实线
                        }
                      }
                    }
                  });
                } else if (item.type === "fund") {
                  //数据1 添加双向绑定key
                  this.$set(
                    this.selectedLegend,
                    item.name,
                    typeof this.selectedLegend[item.name] === "boolean"
                      ? this.selectedLegend[item.name]
                      : true
                  );
                  fundData = item;
                } else if (item.type === "fund|draw_down") {
                  // 数据4
                  retracementData = item;
                }
              });
            }
            // 开始绘图
            this.performanceOption = {
              title: {
                show: this.isShowChart,
                text: "数据准备中",
                left: "center",
                top: "center",
                textStyle: {
                  fontSize: 16,
                  fontWeight: 400
                }
              },
              legend: [
                {
                  data: legends,
                  top: "2%",
                  left: "25%",
                  right: "10%",
                  selected: this.selectedLegend
                },
                {
                  data: ["数据4"],
                  top: "73%",
                  right: "0%"
                }
              ],
              dataZoom: [
                {
                  id: "dataZoomX",
                  type: "slider",
                  xAxisIndex: [0, 1],
                  height: 20,
                  top: "65%",
                  right: 10,
                  left: 10,
                  handleIcon:
                    "M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z",
                  handleSize: "80%",
                  fillerColor: "rgba(255, 76, 31,.2)",
                  dataBackground: {
                    areaStyle: {
                      color: ""
                    },
                    lineStyle: {
                      opacity: 1,
                      color: "#FF4C1F"
                    }
                  },
                  handleStyle: {
                    color: "#FF4C1F"
                  },
                  filterMode: "weakFilter",
                  zoomOnMouseWheel: "false"
                }
              ],
              tooltip: {
                trigger: "axis",
                axisPointer: { type: "cross" },
                formatter: function (datas) {
                  let res = datas[0].name + "<br/>";
                  let length = datas.length;
                  let i = 0;
                  for (; i < length; i++) {
                    res += `
                    <span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${
                      datas[i].color
                    };"></span>
                    ${datas[i].seriesName}: ${
                      datas[i].value != null
                        ? datas[i].value.toFixed(4)
                        : "无数据"
                    }
                    <br/>
                    `;
                  }
                  return res;
                }
              },
              axisPointer: {
                // 坐标轴指示器
                link: { xAxisIndex: "all" },
                label: { backgroundColor: "#777" }
              },
              grid: [
                {
                  top: 40,
                  left: 10,
                  right: 0,
                  bottom: 20,
                  height: "60%"
                },
                {
                  left: 10,
                  right: 0,
                  bottom: 15,
                  height: "20%"
                }
              ],
              xAxis: [
                {
                  type: "category",
                  data: dts,
                  axisLine: {
                    show: true,
                    lineStyle: {
                      color: "#D8D8D8"
                    }
                  },
                  axisTick: {
                    show: false
                  },
                  axisLabel: {
                    show: true,
                    textStyle: {
                      fontSize: 10,
                      color: "#222831"
                    }
                  },
                  splitLine: {
                    show: false
                  },
                  scale: true
                },
                {
                  type: "category",
                  gridIndex: 1,
                  data: dts,
                  axisLine: {
                    lineStyle: {
                      color: "#D8D8D8"
                    }
                  },
                  scale: true,
                  axisTick: { show: false },
                  splitLine: { show: false },
                  axisLabel: { show: false }
                }
              ],
              yAxis: [
                {
                  scale: true,
                  splitArea: {
                    show: false
                  },
                  splitNumber: 4,
                  axisLabel: {
                    show: true,
                    textStyle: {
                      fontSize: 10,
                      color: "#808080",
                      align: "left"
                    }
                  },
                  axisLine: {
                    show: false,
                    lineStyle: {
                      color: "#D8D8D8"
                    }
                  },
                  axisTick: {
                    show: false
                  },
                  splitLine: {
                    show: true,
                    lineStyle: {
                      color: "#F5F5F5"
                    }
                  }
                },
                {
                  type: "value",
                  gridIndex: 1,
                  offset: -10,
                  axisLabel: {
                    show: true,
                    textStyle: { fontSize: 10, color: "#808080", align: "left" }
                  },
                  axisLine: { show: false },
                  axisTick: { show: false },
                  splitLine: { show: false }
                }
              ],
              series: [
                ...simulation, // 数据3
                ...fund_account, // 数据2
                {
                  name: fundData.name,
                  type: "line",
                  data: fundData.data,
                  color: "#FF7979",
                  symbol: false,
                  symbolSize: 0, // 拐点圆的大小
                  areaStyle: {
                    // 折线渐变阴影
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                      {
                        offset: 0,
                        color: "#FEE1E1"
                      },
                      {
                        offset: 0.76,
                        color: "#FFF8F8"
                      }
                    ])
                  },
                  markLine: {
                    lineStyle: { width: 2 }, // 标线大小
                    data: [
                      {
                        name: "标线1",
                        yAxis: this.fundInfo.warning_line,
                        lineStyle: {
                          color: "#FFAE00"
                        },
                        0: {
                          // type: "average",
                          symbol: "image://@/assets/task_status/success.png"
                        },
                        1: {
                          symbol: "none"
                        }
                      },
                      {
                        name: "标线2",
                        yAxis: this.fundInfo.liquidation_line,
                        lineStyle: {
                          color: "#FF4A00"
                        },
                        0: {
                          symbol: "none"
                        },
                        1: {
                          symbol: "none"
                        }
                      }
                    ]
                  }
                },
                {
                  name: "数据4",
                  type: "line",
                  data: retracementData.data,
                  color: "#6C9EF8",
                  gridIndex: 1,
                  xAxisIndex: 1,
                  yAxisIndex: 1,
                  symbolSize: 0, // 拐点圆的大小
                  areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                      {
                        offset: 0,
                        color: "rgba(115,156,250,0.05)"
                      },
                      {
                        offset: 0.76,
                        color: "rgba(115,156,250,0.25)"
                      }
                    ])
                  }
                }
              ]
            };
          },
          // 重点看这里,下载曲线数据
          handleDownload() {
            const fundPerformance_dt = this.fundPerformanceData;
            const rows = []; // 整理后的数据
            const fields = [];
            fundPerformance_dt.forEach((item) => {
              fields.push(item.name);
            });
            let firstFieldData = fundPerformance_dt.find(
              (item) => item.name === fields[0]
            ).data;
            for (let i = 0; i < firstFieldData.length; i++) {
              let tempData = {};
              for (const field of fields) {
                tempData[field] = fundPerformance_dt.find(
                  (item) => item.name === field
                ).data[i];
              }
              rows.push(tempData);
            }

            // 在这里导出文件
            const fileName = "data";
            const result = json2csv.parse(rows, {
              fields: fields,
              excelStrings: true
            });
            if (this.MyBrowserIsIE()) {
              // IE10以及Edge浏览器
              const BOM = "\uFEFF";
              // 文件转Blob格式
              const csvData = new Blob([BOM + result], { type: "text/csv" });
              navigator.msSaveBlob(csvData, `${fileName}.csv`);
            } else {
              const csvContent = "data:text/csv;charset=utf-8,\uFEFF" + result;
              // 非ie 浏览器
              const link = document.createElement("a");
              link.href = encodeURI(csvContent);
              link.download = fileName;
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);
            }
          }
        }
}
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
最后更新时间: 6/20/2022, 10:48:50 PM