【发布时间】:2017-01-17 21:23:54
【问题描述】:
如何从包含 1200 行和 13 列的 csv 数据文件中选择将在 C3.js 中绘制图形的列。 附录:我已经编辑了文件并进行了更改。该文件有效。所有问题都解决了。对于一般信息,我从 JSFiddle 页面的副本中检索了基本文档。显然,每个 JSFiddle 页面源代码都包含指向 JSFiddle 上代码的两个(离线)功能副本的链接。 JSFiddle 页面中编写的代码无法离线工作。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">
<script type="text/javascript" src="./resources/d3.v3.min.js"></script>
<script type="text/javascript" src="./resources/c3.js"></script>
<link rel="stylesheet" type="text/css" href="./resources/c3.css">
<style type="text/css"></style>
<title>once again</title>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
d3.csv("./data/dataXY_11-21-2016.csv")
.row(function(d) { return [d.time12, d.PVpower, d.Elevation]; })
.get(function(error,rows) {
rows.unshift (["time 12", "PV array power(W)", "Elevation"])
console.log(rows);
var chart = c3.generate({
size:{
width: 1000,
height: 400
},
bindto: '#chart',
data: {
rows: rows,
type: 'line',
x: 'time 12',
xFormat:'%I:%M:%S %p'
},
point: {show: false},
tooltip: {show: false},
axis: {
x: {
localtime: true,
type:'timeseries',
tick:{
//culling:{max: 50},
fit: true,
count: 50,
format: '%I:%M:%S %p',
rotate: 65,
}//end tick
},//end x
y: {
max: 350,
min: 0
} //end y
},//end axis
grid:{
x:{
show: true
},//end x
y:{
show: true
}//end y
}//end grid
});
});
}//]]>
</script>
<body>
<div id="chart"></div>
<script>
if (window.parent && window.parent.parent){
window.parent.parent.postMessage(["resultsFrame", {
height: document.body.getBoundingClientRect().height,
slug: "None"
}], "*")
}
</script>
</body>
</html>
【问题讨论】:
-
看这里的问题 --> stackoverflow.com/questions/26521945/… 。基本上,您必须首先在生成 c3 图表之外过滤 csv。然后在 c3 图表生成函数中使用过滤后的数据。
-
从脚本中可以看出,我采用了解决方案 #2,但它并没有按原样工作。
-
但是您正在尝试在 c3 generate 函数中进行 csv 过滤。它需要在此之外完成。
-
我已经修改了脚本以进行其他更改,如上所示。我还在生成脚本之前和之后将过滤器插入到它自己的脚本中。不去。我在生成函数之前和之后将过滤器插入到与生成函数相同的脚本中。不行。
-
哦,'columns'函数也没有效果。
标签: c3.js