Metricsgraphics日期访问-折线图
Metricsgraphics Date access - Line graph
我正在使用MetricsGraphic库进行D3可视化。出于某种原因,我不明白为什么我的日期解析不起作用。
d3.json('/api/data', function (data){
data = MG.convert.date(data, "Date"["%d/%m/%y"]);
MG.data_graphic({
title: "Points per Matchday",
description: "Points earned each matchday of 2014/2015 season",
data: dataSet,
width: 600,
height: 200,
right: 40,
target: document.getElementById('arsenalPoints'),
x_accessor: 'Date',
y_accessor: 'Points'
});
});
我一直收到一个类型错误,说它是can't read property of 'time' undefined
和我的MG.convert.date
函数。我也不知道我的日期格式是否正确。
下面是我的JSON示例:
{
"Date" : "26/04/15",
"HomeTeam" : "Arsenal",
"AwayTeam" : "Chelsea",
"FTR" : "D",
"Points": 1
}
一种方法是使用MG:
这是错误的:
data = MG.convert.date(data, "Date"["%d/%m/%y"]);
这是正确的:
data = MG.convert.date(data, "Date", "%d/%m/%y");//its not an array
以下的完整代码
d3.json('/api/data', function (data){
data = MG.convert.date(data, "Date", "%d/%m/%y");//its not an array
MG.data_graphic({
title: "Points per Matchday",
description: "Points earned each matchday of 2014/2015 season",
data: data, // Send in our data
width: 600,
height: 200,
right: 40,
target: document.getElementById('arsenalPoints'),
x_accessor: 'Date',
y_accessor: 'Points'
});
});
另一种方法是使用d3:转换日期
d3.json('/api/data', function (data){
data.forEach(function(j){
j.Date = d3.time.format("%d/%m/%y").parse(j.Date);//convert it into date
});
MG.data_graphic({
title: "Points per Matchday",
description: "Points earned each matchday of 2014/2015 season",
data: data, // Send in our data
width: 600,
height: 200,
right: 40,
target: document.getElementById('arsenalPoints'),
x_accessor: 'Date',
y_accessor: 'Points'
});
});
相关文章:
- 用与线条相同的颜色填充多折线图上的点
- 跟踪jqplot垂直折线图的鼠标位置
- Morris.js折线图x轴标签在调整大小后消失
- Chart.js V2折线图缺点
- 将直流图表库中的折线图缩放限制为小时
- 如何用d3.js绘制折线图
- 部分填充区域的折线图
- 将时间缩放添加到折线图(Chart.js)
- Chart.js折线图的0线型
- d3绘制动画折线图的基本示例
- Javascript FLOT组合条形图;以x轴为字符串的折线图
- 如何在折线图中显示最近的值
- charts js更改折线图轴的字体大小/颜色和背景线
- 从特定系列的谷歌可视化折线图中删除悬停工具提示
- D3折线图鼠标悬停坐标效果
- Metricsgraphics日期访问-折线图
- 折线图自定义X值访问器
- 在D3多折线图的工具提示中访问数据
- dc.js折线图分组后的访问值
- D3.js:访问数组中的对象属性以创建折线图