console
function timeScaleChartFun() {
console.info("callback:" + this);
}
window.onload = function () {
var timeOpts = {};
var canvas = document.getElementById("Chart");
canvas.width = 600;
canvas.height = 600;
canvas.style.width = "600px";
canvas.style.height = "600px";
timeOpts.mW = canvas.width
timeOpts.mH = canvas.width
timeOpts.lineWidth = 10
timeOpts.r = timeOpts.mW / 2;
timeOpts.cR = timeOpts.r - 4 * timeOpts.lineWidth;
timeOpts.startAngle = -(1 / 2 * Math.PI);
timeOpts.endAngle = timeOpts.startAngle + 2 * Math.PI;
timeOpts.xAngle = 1 * (Math.PI / 180);
timeOpts.fontSize = 55;
timeOpts.tmpAngle = timeOpts.startAngle;
timeOpts.startTemp = 10;
timeOpts.callback = timeScaleChartFun;
var chart = new TimeScaleChart(canvas, timeOpts);
chart.init();
}
function TimeScaleChart(canvas, options) {
this.canvas = canvas;
this.options = options
this.ctx = canvas.getContext("2d");
var _this = this;
this.canvas.addEventListener('touchmove', function (evt) {
var selectX = evt.changedTouches[0];
console.log(selectX)
console.log(_this.options.tmpAngle)
_this.update(options);
});
}
TimeScaleChart.prototype.init = function () {
var _this = this;
_this.draw();
this.inited = true;
}
TimeScaleChart.prototype.update = function (options) {
this.options = options;
if (this.inited) {
this.init();
}
}
TimeScaleChart.prototype.draw = function () {
var _this = this;
if(this.options.tmpAngle >= this.options.endAngle){
return;
}else if(this.options.tmpAngle + this.options.xAngle > this.options.endAngle){
this.options.tmpAngle = this.options.endAngle;
}else{
this.options.tmpAngle += this.options.xAngle;
}
this.ctx.clearRect(0, 0, this.options.mW, this.options.mH);
this.ctx.save();
this.ctx.beginPath();
this.ctx.lineWidth = this.options.lineWidth;
this.ctx.strokeStyle = '#1c86d1';
this.ctx.translate(this.options.r, this.options.r);
this.ctx.rotate(-Math.PI * 0.5);
for(var i = 0; i <= this.options.tmpAngle - this.options.startAngle; i += this.options.xAngle){
this.ctx.moveTo(0, this.options.cR - this.options.lineWidth);
this.ctx.lineTo(0, this.options.cR);
this.ctx.rotate(this.options.xAngle);
}
this.ctx.stroke();
this.ctx.closePath();
this.ctx.restore();
this.ctx.fillStyle = '#1d89d5';
this.ctx.font= this.options.fontSize + 'px Microsoft Yahei';
this.ctx.textAlign='center';
this.ctx.fillText( Math.round((this.options.tmpAngle - this.options.startAngle) / (this.options.endAngle - this.options.startAngle) * 50) + '℃', this.options.r, this.options.r + this.options.fontSize / 2);
}
<canvas id="Chart" width="" height="500"></canvas>