nodejs 数据处理和绘制图表显示 替代matlab效果

技术分享 2022-04-06 12:45:07

数据计算直接用nodejs提供 一个本地http服务


var http = require('http');
http.createServer(function (request, response) {
    response.setHeader("Access-Control-Allow-Origin", "*")
    response.writeHead(200, {'Content-Type': 'text/plain'})

    //
    let indata = fs.readFileSync('./point0_resp.txt').toString();
    let outArray = [];
    for (let index = 0; index < indataArray.length; index++) {
        if (index%3 == 0) {
            outArray.push(indataArray[index])
        }
    }

    response.end(JSON.stringify(outArray));
}).listen(8081);

console.log('Server running at http://127.0.0.1:8081/');


图表和显示端:

直接用echart 在线代码显示  :顺便加个放大和鼠标经过数值显示功能

https://echarts.apache.org/examples/zh/editor.html?c=line-simple

option = {
  xAxis: {
    type: 'category'
  },
  yAxis: {
    type: 'value'
  },
  
  toolbox: {
     show:true,
     feature:{
      dataZoom: {
       yAxisIndex:"none"
      },
      //其他功能性按钮查看官网进行增加,包括(显示数据,下载图片,改为柱状图等)
     }
    },
     tooltip : {
            trigger: 'axis',
            axisPointer: {
              type: 'cross',
              label: {
                backgroundColor: '#6a7985'
              }
            }
        },
  series: [
    {
      data: [150, 230, 224, 218, 135, 147, 260],
      type: 'line'
    }
  ]
};



//ajax 获取处理过的数据
fetch('http://127.0.0.1:8081/')
  .then(function(response) {
    return response.json();
  })
  .then(function(myJson) {
    // console.log(myJson);
    myChart.setOption({
          series: [
            {
              data: myJson,
            }
          ]
    })
  });
咨询小瓶科技
咨询我们
顶部