1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| drawStatic() { let tickSize = 6;
this.xTick = this.custom .append("g") .attr("class", "axis axisX") .call(this.xAxis) .selectAll("g.tick"); this.ctx.save(); this.ctx.beginPath(); this.xTick.each((el, index, arr) => { let node = d3.select(arr[index]); let xTrans = node.attr("transform"); let xPos = Number(xTrans.split(",")[0].split("(")[1]) + this.chartLeft;
if (index === 0) return;
this.ctx.moveTo(xPos, this.chartTop); this.ctx.lineTo(xPos, this.chartTop + this.chartHeight); }); this.ctx.setLineDash([4, 6]); this.ctx.lineWidth = 2; this.ctx.strokeStyle = "#efefef"; this.ctx.stroke(); this.ctx.restore();
this.ctx.textAlign = "center"; this.ctx.textBaseline = "top"; this.xTick.each((el, index, arr) => { let node = d3.select(arr[index]); let xTrans = node.attr("transform"); let xPos = Number(xTrans.split(",")[0].split("(")[1]) + this.chartLeft;
this.ctx.fillText( node.property("innerText"), xPos, this.chartTop + this.chartHeight ); });
this.ctx.save(); this.ctx.textAlign = "center"; this.ctx.textBaseline = "top"; this.ctx.font = "16px sans-serif"; this.ctx.fillText( "件數", this.conWidth / 2, this.chartTop + this.chartHeight + 30 ); this.ctx.restore();
this.yTick = this.custom .append("g") .attr("class", "axis axisY") .call(this.yAxis) .selectAll("g.tick"); this.ctx.beginPath(); this.yTick.each((el, index, arr) => { let node = d3.select(arr[index]); let yTrans = node.attr("transform"); let yPos = Number(yTrans.split(",")[1].split(")")[0]) + this.chartTop;
if (index === 0) return;
this.ctx.moveTo(this.chartLeft - tickSize, yPos); this.ctx.lineTo(this.chartLeft, yPos); }); this.ctx.stroke(); this.ctx.beginPath(); this.ctx.moveTo( this.chartLeft - tickSize, this.chartTop + this.chartHeight ); this.ctx.lineTo(this.chartLeft, this.chartTop + this.chartHeight); this.ctx.stroke();
this.ctx.beginPath(); this.ctx.moveTo(this.chartLeft, this.chartTop); this.ctx.lineTo(this.chartLeft, this.chartTop + this.chartHeight); this.ctx.stroke();
this.ctx.textAlign = "right"; this.ctx.textBaseline = "middle"; this.yTick.each((el, index, arr) => { let node = d3.select(arr[index]); let yTrans = node.attr("transform"); let yPos = Number(yTrans.split(",")[1].split(")")[0]) + this.chartTop;
this.ctx.fillText( node.property("innerText"), this.chartLeft - tickSize, yPos ); }); },
|