I'm shooting for at least one post a month and I'm on a two month roll. This month's entry is about a feature not available to all. Those of you on IE, Firefox and Opera can move along. Those with Safari and Chrome can hang around. Unfortunately, this cool feature doesn't work with Safari on the iphone, at least not v2.0.One of the new cool things that comes with HTML5 support is canvas. Using canvas you can write graphics directly to the browser. The chart image was made using canvas and a little chart api I wrote a while back in .net. I converted the api to javascript. I only moved over the bar chart though there are a few other charts still in .net. I'll move them over when I get a chance. I'm thinking of changing up holeytwit to track and cache the top searches over time and use the chart canvas api to chart out the results.To see iCanChart and canvas in action click on the image or this link.To get started with canvas, you need to create a ..... you guessed it a ..... canvas tag.
<body onload="draw()"> <canvas id="canvas1" width="500" height="300"></canvas> </body>
<script type="text/javascript" src="../script/iCanChart.js"></script><script type="text/javascript"> function draw(){ var bc = new BarChart; var dataPoints = new Array(); // build out the data points for(var i=0;i<10;i ){ dataPoints[i] = new Object(); dataPoints[i].Label = 'day ' (i 1); dataPoints[i].Value = Math.random()*100; } // create the chart bc.initBarChart('canvas1',300,500,dataPoints,'Hits per Day','hits'); } </script>
</script>
function canvasElement(){ return document.getElementById(this.canvasId).getContext('2d');}function drawLine(_color,_width,_x1,_y1,_x2,_y2){ var ctx = this.canvasElement(); ctx.beginPath(); ctx.strokeStyle = _color; ctx.lineWidth = _width; ctx.moveTo(_x1,_y1); ctx.lineTo(_x2,_y2); ctx.stroke(); ctx.closePath();}function drawRectangle(_color,_x,_y,_height,_width){ var ctx = this.canvasElement(); ctx.beginPath(); ctx.fillStyle = _color; ctx.fillRect(_x,_y,_width,_height); ctx.fill(); ctx.closePath();}function drawText(_color,_align,_font,_text,_x,_y){ var ctx = this.canvasElement(); ctx.beginPath(); ctx.font = _font; ctx.textAlign = _align; ctx.fillStyle = _color; ctx.fillText(_text, _x, _y); ctx.fill(); ctx.closePath();}