嗨,你能帮我设置这个代码吗?我不太擅长 html5。
如果您的浏览器不支持 HTML5 Canvas,则会显示此文本。
$(document).ready(function() { // initialize some variables for the chart var canvas = $("#canvas")[0]; var ctx = canvas.getContext('2d'); var data = [75,68,32,95,20,51]; var colors = ["#7E3817", "#C35817", "#EE9A4D", "#A0C544", "#348017", "#307D7E"]; var center = [canvas.width / 2, canvas.height / 2]; var radius = Math.min(canvas.width, canvas.height) / 2; var lastPosition = 0, total = 0; var pieData = []; // total up all the data for chart for (var i in data) { total += data[i]; } // populate arrays for each slice for(var i in data) { pieData[i] = []; pieData[i]['value'] = data[i]; pieData[i]['krasa'] = colors[i]; pieData[i]['startAngle'] = 2 * Math.PI * lastPosition; pieData[i]['endAngle'] = 2 * Math.PI * (lastPosition + (data[i]/total)); lastPosition += data[i]/total; } function drawChart() { for(var i = 0; i < data.length; i++) { var gradient = ctx.createLinearGradient( 0, 0, canvas.width, canvas.height ); gradient.addColorStop( 0, "#ddd" ); gradient.addColorStop( 1, colors[i] ); ctx.beginPath(); ctx.moveTo(center[0],center[1]); ctx.arc(center[0],center[1],radius,pieData[i]['startAngle'],pieData[i]['endAngle'],false); ctx.lineTo(center[0],center[1]); ctx.closePath(); ctx.fillStyle = gradient; ctx.fill(); ctx.lineWidth = 1; ctx.strokeStyle = "#fff"; ctx.stroke(); } } drawChart(); // first render });
如何为每个切片添加悬停效果?