我有一些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>
当我将 as 分配给XAxis组件的域时,它会记录域: 数组[4474] 而不是 [星期六2017年4月4日14:16:51 GMT + 0100(浪漫标准时间),2017年5月5日星期五14:16:51 GMT + 0200(浪漫日光时间)] ,它没有为X轴设置正确的域。
任何形式的帮助将不胜感激!!!