我有制表符分隔文件,其字段名称如下
cut -f1 common.csv | head
job_id
1
2
"job2 txt
job2_txt
job2 txt"
在job_txt字段下,数据将具有上面的新行字符
[{
"date": "2016-10-12T00:00:00.000Z",
"parameter": "end_brick_temperature",
"value": 61.3,
"color": "green"
}, {
"date": "2016-10-12T00:00:00.000Z",
"parameter": "percentage_of_expected_messages_received",
"value": 99.6667,
"color": "green"
}, {
"date": "2016-10-12T00:00:00.000Z",
"parameter": "energy_used_kwh",
"value": 1.73418,
"color": "orange"
}, {
"date": "2016-10-12T08:00:00.000Z",
"parameter": "energy_used_kwh",
"value": 0.70354,
"color": "red"
}, {
"date": "2016-10-12T08:00:00.000Z",
"parameter": "end_brick_temperature",
"value": 57.7,
"color": "green"
}, {
"date": "2016-10-12T08:00:00.000Z",
"parameter": "percentage_of_expected_messages_received",
"value": 98.3333,
"color": "green"
}, {
"date": "2016-10-12T16:00:00.000Z",
"parameter": "percentage_of_expected_messages_received",
"value": 99.1667,
"color": "green"
}, {
"date": "2016-10-12T16:00:00.000Z",
"parameter": "energy_used_kwh",
"value": 0,
"color": "red"
}, {
"date": "2016-10-12T16:00:00.000Z",
"parameter": "end_brick_temperature",
"value": 42.2,
"color": "green"
}, {
"date": "2016-10-13T00:00:00.000Z",
"parameter": "energy_used_kwh",
"value": 1.73979,
"color": "orange"
}, {
"date": "2016-10-13T00:00:00.000Z",
"parameter": "end_brick_temperature",
"value": 66.2
}, {
"date": "2016-10-13T00:00:00.000Z",
"parameter": "percentage_of_expected_messages_received",
"value": 99.3333,
"color": "green"
}, {
"date": "2016-10-13T08:00:00.000Z",
"parameter": "end_brick_temperature",
"value": 59.8,
"color": "green"
}, {
"date": "2016-10-13T08:00:00.000Z",
"parameter": "energy_used_kwh",
"value": 0.711456,
"color": "red"
}, {
"date": "2016-10-13T08:00:00.000Z",
"parameter": "percentage_of_expected_messages_received",
"value": 98.3333,
"color": "green"
}]
当我执行上面的代码时,输出第一个字段的common.csv就像下面的
var xScale = new Plottable.Scales.Time().domain([data[0].date, data[data.length - 1].date]);
var xAxisDate = new Plottable.Axes.Time(xScale, "bottom");
var yScale = new Plottable.Scales.Category();
var yAxisParameters = new Plottable.Axes.Category(yScale, "left");
var plot = new Plottable.Plots.Rectangle()
.addDataset(new Plottable.Dataset(data))
.x(function (d) {
return d.date
}, xScale)
.y(function (d) {
return d.parameter
}, yScale)
.attr("fill", function (d) {
return d.color
});
var table = new Plottable.Components.Table([
[yAxisParameters, plot],
[null, xAxisDate]
]);
table.renderTo("svg#heatmap");
有人可以帮助我吗