課程
/前端開發(fā)
/Html5
/使用D3制作圖表
求課程示例代碼
2017-07-14
源自:使用D3制作圖表 2-1
正在回答
var?width?=?500, ????height?=?250, ????margin?=?{left:?50,?top:?30,?right:?20,?bottom:?20}, ????g_width?=?width?-?margin.left?-?margin.right, ????g_height?=?height?-?margin.top?-?margin.bottom; //?類似jq的鏈?zhǔn)秸{(diào)用 //?制作圖中的線條 var?svg?=?d3.select('#container') ????.append("svg:svg") ????//?width,height ????.attr('width',?width)//attribute ????.attr('height',?height); var?g?=?svg.append("g") ????.attr("transform",?"translate("?+?margin.left?+?","?+?margin.top?+?")"); var?data?=?[1,?3,?5,?7,?8,?4,?3,?7]; //?放大 var?scale_x?=?d3.scaleLinear() ????.domain([0,?data.length?-?1]) ????.range([0,?g_width]); var?scale_y?=?d3.scaleLinear() ????.domain([0,?d3.max(data)]) ????.range([g_height,?0]);//?切換坐標(biāo)軸的朝向 var?line_generator?=?d3.line() ????.x(function?(d,?i)?{ ????????//?d代表數(shù)據(jù) ????????//?i代表下標(biāo) ????????return?scale_x(i); ????}) ????.y(function?(d)?{ ????????return?scale_y(d); ????}) ????.curve(d3.curveCatmullRom.alpha(0.5)); g.append('path').attr('d',?line_generator(data)); //?制作坐標(biāo)軸 var?x_axis?=?d3.axisBottom(scale_x), ????y_axis?=?d3.axisLeft(scale_y); g.append("g").call(x_axis) ????.attr("transform",?"translate(0,"?+?g_height?+?")"); g.append("g").call(y_axis) ????.append("text").text("Price($)")?//?設(shè)置單位等 ????.attr("transform",?"rotate(-90)")?//?定位 ????.attr("text-anchor",?"end") ????.attr("dy",?"1em");
#container?{ ??background:?#ddd; ??width:?500px; ??height:?250px; } path?{ ??fill:?none; ??stroke:?#4682B4; ??stroke-width:?2; } text?{ ??fill:?#000; } .domain, .tick?line?{ ??stroke:?gray; }
舉報(bào)
教你使用最酷的數(shù)據(jù)可視化圖表,初探數(shù)據(jù)可視化奧秘
4 回答求使用D3制作圖表課程源代碼
1 回答使用D3制作圖表第二章:畫線圖代碼和視頻上一樣,效果不顯示,求助0.0
1 回答請(qǐng)問有課程代碼嗎?
1 回答我想說有代碼下載嗎??
5 回答為什么我顯示出來是亂碼?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-08-15