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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| drawStatic() { let tickSize = 6;
this.xTick = this.custom .append("g") .attr("class", "axis axisX") .call(this.xAxis) .selectAll("g.tick"); 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.chartHeight); this.ctx.lineTo(xPos, this.chartTop + this.chartHeight + tickSize); }); this.ctx.stroke();
this.ctx.beginPath(); this.ctx.moveTo(this.chartLeft, this.chartTop + this.chartHeight); this.ctx.lineTo( this.chartLeft + this.chartHeight, this.chartTop + this.chartWidth ); this.ctx.stroke();
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 + tickSize ); });
this.data.forEach((el, index) => { this.ctx.save(); this.ctx.beginPath(); this.ctx.arc( this.chartLeft + index * 100, this.chartTop + this.chartHeight + 50, 5, 0, 2 * Math.PI ); this.ctx.fillStyle = this.color(index); this.ctx.fill(); this.ctx.closePath();
this.ctx.textAlign = "left"; this.ctx.textBaseline = "middle"; this.ctx.font = "16px sans-serif"; this.ctx.fillStyle = "#000"; this.ctx.fillText( el.name, this.chartLeft + index * 100 + 10, this.chartTop + this.chartHeight + 50 ); this.ctx.restore(); });
this.yTick = this.custom .append("g") .attr("class", "axis axisY") .call(this.yAxis) .selectAll("g.tick"); this.ctx.save(); 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, yPos); this.ctx.lineTo(this.chartLeft + this.chartWidth, yPos); }); this.ctx.strokeStyle = "#efefef"; this.ctx.stroke(); this.ctx.restore();
this.ctx.beginPath(); this.ctx.moveTo(this.chartLeft - tickSize, this.chartTop); this.ctx.lineTo(this.chartLeft, this.chartTop); 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 ); });
this.ctx.save(); this.ctx.translate(0, 0); this.ctx.rotate(-Math.PI / 2); this.ctx.textAlign = "center"; this.ctx.textBaseline = "top"; this.ctx.font = "16px sans-serif"; this.ctx.fillText("件數", -(this.chartTop + this.chartHeight / 2), 0); this.ctx.restore(); },
|