0
我有興趣創建一個折線圖 - 繪製本身從左至右 - 在x軸基本連接點。
http://bl.ocks.org/markmarkoh/8700606 http://bl.ocks.org/duopixel/4063326
這是我做了,開始創建這個圖表的jsfiddle。 http://jsfiddle.net/NYEaX/1512/
//__invoke line
$('[data-role="line"]').each(function(index) {
createLine(this);
});
function createLine(el){
var w = $(el).data("width");
var h = $(el).data("height");
var svg = d3.select($(el)[0])
.append("svg")
.attr("width", w)
.attr("height", h);
var data = d3.range(11).map(function(){return Math.random()*10})
var x = d3.scale.linear().domain([0, 10]).range([0, 700]);
var y = d3.scale.linear().domain([0, 10]).range([10, 290]);
var line = d3.svg.line()
.interpolate("cardinal")
.x(function(d,i) {return x(i);})
.y(function(d) {return y(d);})
var path = svg.append("path")
.attr("d", line(data))
.attr("stroke", "steelblue")
.attr("stroke-width", "2")
.attr("fill", "none");
var totalLength = path.node().getTotalLength();
path
.attr("stroke-dasharray", totalLength + " " + totalLength)
.attr("stroke-dashoffset", totalLength)
.transition()
.duration(2000)
.ease("linear")
.attr("stroke-dashoffset", 0);
svg.on("click", function(){
path
.transition()
.duration(2000)
.ease("linear")
.attr("stroke-dashoffset", totalLength);
});
/* plot axis */
var padding = 100; // space around the chart, not including labels
// define the x axis
var xAxis = d3.svg.axis()
.orient("bottom")
.scale(x);
//.tickFormat(date_format);
// draw x axis with labels and move to the bottom of the chart area
svg.append("g")
.attr("class", "xaxis axis") // two classes, one for css formatting, one for selection below
.attr("transform", "translate(0," + (h - padding) + ")")
.call(xAxis);
/* plot axis */
}
是的,這就是好男人 - 我會怎麼收拾軸 - 去除黑線基本上是 - 我不知道還如何與日期範圍創建一些假的JSON數據如果確實要將x尺度調整到一個時間尺度? –
如果你想改變最小的代碼量,我已經更新了小提琴以模仿上面的圖像:http://jsfiddle.net/stancheta/ystymLm4/7/並放入一些評論來解釋我改變了什麼。讓我知道他們是否不清楚。 –
這看起來不錯的男人 - 有一個賞金,如果你想幫助解決這個部分--- http://stackoverflow.com/questions/39156400/d3-animating-a-bubble-chart-within-a-given-半徑/ 39197206#39197206 –