0

我有一些 JSON 包含在一个数组中,其中包含 4474 个对象,如下所示:

data: [
 {
   "T": "2017-02-04 14:16:51",
   "Min": 0,
   "Max": 0,
   "Average": 0
 },
 {
   "T": "2017-03-27 14:51:23",
   "Min": 0,
   "Max": 0,
   "Average": 0
 },
 {
   "T": "2017-03-27 14:53:23",
   "Min": 0,
   "Max": "1,7",
   "Average": "0,1"
 },
 {
   "T": "2017-03-27 15:23:23",
   "Min": "1,6",
   "Max": "1,6",
   "Average": "1,6"
 },
............
............4473,
{
   "T": "2017-05-05 14:16:51",
   "Min": "1,3",
   "Max": "1,3",
   "Average": "1,3"
 }
];

我正在尝试以 T 作为 X 轴,Max 作为 Y 轴来绘制折线图。我写了一些代码,如下所示:

let da = data.data;
let as = d3.extent(da, item => Parse(item.T)); // [Sat Feb 04 2017 14:16:51 GMT+0100 (Romance Standard Time), Fri May 05 2017 14:16:51 GMT+0200 (Romance Daylight Time)]
let bs =  d3.extent(da, item => item.Max); //  [0,17]

<LineChart width={1100} height={650} data={da}
            margin={{top: 5, right: 30, left: 20, bottom: 5}}>
         <XAxis datakey="T" scale={"time"} domain={ as } allowDataOverflowBoolean={true}/>
         <YAxis datakey="Max" scale={"linear"} type="number" domain={bs} allowDataOverflowBoolean={true}/>
        <CartesianGrid strokeDasharray="3 3"/>
         <Tooltip/>
        <Legend />
       <Line type="linear" dataKey="Max" stroke="#8884d8" activeDot={{r: 8}}/>
</LineChart>

当我为 XAxis 组件分配时,它记录域:Array[4474]而不是[Sat Feb 04 2017 14:16:51 GMT+0100 (Romance Standard Time), Fri May 05 14:16:51 GMT+ 0200(浪漫日光时间)],它没有为 X 轴设置正确的域。

在此处输入图像描述

任何形式的帮助将不胜感激!!!

4

0 回答 0