我想要從表單輸入文本框中收集數據,其中用戶填寫了不同餅圖元素的值,然後當他單擊提交按鈕時,使用該標記生成餅圖。我建立了一個測試版本,在這裏固定值:如何存儲用戶數據以創建餅圖?
<form style="margin-bottom: 50px;">
1 value: <input type="number" placeholder="In 100% percentage.." name="first" max="100"><br/>
2 value: <input type="number" placeholder="In 100% percentage.." name="second"max="100" ><br>
3 value: <input type="number" placeholder="In 100% percentage.." name="third" max="100"><br/>
4 value: <input type="number" placeholder="In 100% percentage.." name="fourth" max="100"><br>
</form>
<input type="submit" name="submit" value="Generate Pie-Chart" style="margin-bottom: 30px;">
<section>
<div>
<canvas id="canvas" width="400" height="300">
This text is displayed if your browser does not support HTML5 Canvas.
</canvas>
</div>
<script type="text/javascript">
var myColor = ["#ECD078","#D95B43","#C02942","#542437","#53777A"];
var myData = [100,30,20,60,40];
function getTotal(){
var myTotal = 0;
for (var j = 0; j < myData.length; j++) {
myTotal += (typeof myData[j] == 'number') ? myData[j] : 0;
}
return myTotal;
}
function plotData() {
var canvas;
var ctx;
var lastend = 0;
var myTotal = getTotal();
canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < myData.length; i++) {
ctx.fillStyle = myColor[i];
ctx.beginPath();
ctx.moveTo(200,150);
ctx.arc(200,150,150,lastend,lastend+(Math.PI*2*(myData[i]/myTotal)),false);
ctx.lineTo(200,150);
ctx.fill();
lastend += Math.PI*2*(myData[i]/myTotal);
}
}
plotData();
</script>
,但我想在var myData = [100,30,20,60,40];
來讀取輸入表單用戶插入的值。我如何正確地做到這一點?
如何在用戶單擊生成按鈕後繪製餅圖?
嗨,大家好, 我不能幫助,但看到你的問題似乎是在關係有點我的問題在這裏: http://stackoverflow.com/questions/9781012/form-submission-使用-php-mysql-date-query-to-a-google-visualization-page/9782137#comment12453988_9782137 我希望你能幫助我找到Jeff B.只要讓我知道有什麼不清楚的地方。 – 2012-03-21 03:03:24