recharts中的实时图表

时间:2018-05-09 03:54:52

标签: reactjs recharts

我有一个函数,其中数据以随机顺序出现而不是在一个块中。这是我的阵列:

this.props.data = [
{date: "07", visitors: 0},
{date: "08", visitors: 8},
{date: "09", visitors: 14},
{date: "10", visitors: 17},
{date: "11", visitors: 23},
{date: "12", visitors: 31},
{date: "13", visitors: 40}]

以下图表代码

<LineChart data={this.props.data}>
  <XAxis dataKey='date' label={{ value: "Horas", position: "insideBottom", dy: 10} } />
  <YAxis label={{ value: 'Visitantes', angle: -90, position: 'insideLeft' }}/>
  <Tooltip/>
  <Line type="monotone" dataKey="visitors" stroke="#001529" activeDot={{r: 5}}/>
</LineChart>

问题是,我的最高访客价值在图表上低于第一个。 (提醒:他比第一个大5倍)。 Lowest value

Highest value

我的代码中存在一些问题?或者这是recharts的问题?

1 个答案:

答案 0 :(得分:0)

适合我。 CodePen

const {LineChart, Line, XAxis, YAxis, Tooltip} = Recharts;

const mydata = [
{date: "07", visitors: 0},
{date: "08", visitors: 8},
{date: "09", visitors: 14},
{date: "10", visitors: 17},
{date: "11", visitors: 23},
{date: "12", visitors: 31},
{date: "13", visitors: 40}]

const SimpleLineChart = function() {
    return (
    <LineChart data={mydata} width={600} height={400} margin={{ top: 50, bottom: 50, left:50, right:50}}>
      <XAxis dataKey='date'/>
      <YAxis label='Visitantes'/>
      <Line type="monotone" dataKey="visitors" stroke="#001529" activeDot={{r: 5}}/>
      <Tooltip/>
    </LineChart>
  );
};

ReactDOM.render(
  <SimpleLineChart />,
  document.getElementById('container')
);