nvd3.js eventLineChart を使用してモデル化された時系列のいくつかのポイントを強調しようとしています-より正確には、タイムスタンプを持つjsonオブジェクトがあり、タイムスタンプごとに、この特定の日付に垂直線を追加したいと思います/時間。強調表示されたポイントは、時系列データ ソースに存在しない可能性があり、時系列データのすべてのグループ (ティックなど) にわたってグローバルです。
これをどのように達成できるかについてのアイデアはありますか? - プロットに標準線を追加しようとしました (ハイライトしたいイベントのタイムスタンプに従って y1 と y2 と x を修正しました) が、タイムスタンプを元の時系列と同じ範囲にスケーリングできませんでした。
nv.models.lineChartに基づいて、その目的のために構築し始めたモデルの一部を次に示します。- (ほとんどのコードは lineChart モデルからの単なるコピーであるため、モデルの抜粋です):
nv.models.eventLineChart = function() {
// adds vertical highlights to line chart
"use strict";
var chartEvents = {}
function chart(selection) {
selection.each(function(data) {
// Setup Scales
x = lines.xScale();
y = lines.yScale();
// Setup containers and skeleton of chart
var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-lineChart').append('g');
var g = wrap.select('g');
gEnter.append('g').attr('class', 'nv-eventLinesWrap');
//------------------------------------------------------------
// Main Chart Component(s)
var eventWrap = wrap
.select('.nv-eventLinesWrap')
.selectAll('.nv-eventLines')
.data(function(d) {return d });
eventWrap
.enter()
.append('g')
.attr('class', 'nv-eventLines');
// chartEvents json ==> [{decsription: "test,"timestamp: 1375031820000}]
var eventLine = eventWrap
.selectAll('.nv-eventLine')
.data(chartEvents, function(d){return (d.timestamp)});
var eventLineEnter = eventLine.enter()
.append('line').attr('class', 'nv-eventLine')
.style('stroke-opacity', 0);
// @todo set ymin and ymax
eventLine
.attr('x1', function(d){ return x(d.timestamp);})
.attr('x2', function(d){ return x(d.timestamp);})
.attr('y1', 300)
.attr('y2', 800)
.style('stroke', function(d,i,j) { return color(d,j) })
.style('stroke-opacity', function(d,i) {
return 1;
});
});
return chart;
}
chart.setChartEvents = function(_) {
if (!arguments.length) return chartEvents;
chartEvents = _;
return chart;
};
return chart;}
このモデルは、次を使用して呼び出されます。
nv.addGraph(function() {
var nv3dChart = nv.models.eventLineChart().useInteractiveGuideline(true).setChartEvents(json.chartEvents);
// json.chartEvents >> [{decsription: "EventDescription,"timestamp: 1375031820000}]
nv3dChart.xAxis
.showMaxMin(false);
.tickFormat(function(d) { return d3.time.format("%Y-%m-%d")(new Date(d)) });
nv3dChart.yAxis
.axisLabel(widgetConfig.action.data.kpiName)
.tickFormat(d3.format(',.f'));
var ndg = d3.select(renderToElementId+' svg');
ndg.datum([{
values: json.data,
key: widgetConfig.action.data.tagName
}])
.transition().duration(500);
nv.utils.windowResize(nv3dChart.update);
return nv3dChart;})
現在、このsvg出力を生成するもの(垂直線のみで表示されるイベント)
<g class="nv-eventLines">
<line class="nv-eventLine" x1="1375031820000" x2="1375031820000" y1="300" y2="800" style="stroke: #1f77b4;"></line>
</g>
.. 説明したように、折れ線グラフのスケールに従ってイベント x 値のスケーリングを実装する方法をまだ理解していません。
この問題に関する助けをいただければ幸いです