优化ajax传输数据,针对大型数据集优化ajax请求

需要一些有关ajax用例的帮助。

我需要在大约45 MB的数据上绘制图形,我在单击按钮时发送ajax请求以从服务器获取该数据,然后根据响应在客户端上绘制图形。

问题是由于内容大小而引起的。内容下载时间很长,大约为23秒。我需要将其优化为5秒左右。

有人可以为此用例推荐解决方案吗?

这是ajax函数

function generateGraph() {

$.ajax({

type: "GET",

url: "/test",

success: function (data) {

var records = data;

console.log(records.length);

var x = records[0];

var y = records[1];

Plotly.addTraces('myDiv', [

{

x: x,

y: records[1],

type: 'scattergl',

mode: "line"

},

{

x: x,

y: records[2],

type: 'scattergl',

mode: "line"

},

{

x: x,

y: records[3],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[4],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[5],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[6],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[7],

type: 'scattergl'

}, {

x: x,

y: records[3],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[8],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[9],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[10],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[11],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[12],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[13],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[14],

type: 'scattergl',

mode: "line"

}, {

x: x,

y: records[15],

type: 'scattergl',

mode: "line"

},

{

x: x,

y: records[16],

type: 'scattergl',

mode: "line"

},

{

x: x,

y: records[17],

type: 'scattergl',

mode: "line"

},

{

x: x,

y: records[18],

type: 'scattergl',

mode: "line"

}

]);

}

});

}

Plotly.newPlot('myDiv', [{type: 'scattergl'}], {});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值