-1

I want to display Ekg waves. I use echarts. But there is a small problem with the visualize.

My chart:

enter image description here

But I want to see like this page: https://www.arction.com/lightningchart-js-interactive-examples/examples/lcjs-example-0150-ecg.html

My code is here:

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

option = {
    title: {
        text: '动态数据 + 时间坐标轴'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            animation: false
        }
    },
    xAxis: {
        type: 'category',
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        boundaryGap: [0, '100%'],
        min: -1,
        max: 1,
        splitLine: {
            show: false
        }
    },
    series: [{
        name: '模拟数据',
        type: 'line',
        showSymbol: false,
        hoverAnimation: false,
        data: data
    }]
};

setInterval(function () {

    for (var i = 0; i < 5; i++) {
        data.shift();
        data.push(addData());
    }

    myChart.setOption({
        series: [{
            data: data
        }]
    });
}, 1000);

option && myChart.setOption(option);

So what do I need to set on the graph to show the whole thing from a distance instead of zooming in on the drawn part?

P. Mark
  • 81
  • 1
  • 3
  • 12

1 Answers1

0

You not provided part of code where the bug: you should correct something in addData.

See fixed version.

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);

var start_date = new Date(2021, 0, 1);
var data = [];
var option;

function randomData() {
  var date = start_date.setDate(start_date.getDate() + 1)
  return {
    name: date.toString(),
    value: [date, (Math.random() - 0.5) * 2]
  }
}

option = {
  title: {
    text: '动态数据 + 时间坐标轴'
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      animation: false
    }
  },
  xAxis: {
    type: 'time',
    splitLine: {
      show: false
    }
  },
  yAxis: {
    type: 'value',
    boundaryGap: [0, '100%'],
    min: -1,
    max: 1,
    splitLine: {
      show: false
    }
  },
  series: [{
    name: '模拟数据',
    type: 'line',
    showSymbol: false,
    hoverAnimation: false,
    data: data
  }]
};

setInterval(function() {
  if (data.length > 10) {
    data.shift()
  }
  data.push(randomData());

  myChart.setOption({
    series: [{
      data: data
    }]
  });
}, 1000);

myChart.setOption(option);
<script src="https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js"></script>
<div id="main" style="width: 600px;height:400px;"></div>
Sergey Fedorov
  • 3,696
  • 2
  • 17
  • 21