Visualize Traffic with DIY Vector

you will learn how to create your own traffic chart using the incredibly cool Canvas framework, which can produce vector graphics and animations with a little bit of HTML and JavaScript. All code referenced in this hack is also available in a single zip file at http://blogoscoped.com/googleappshacks/canvas.zip. Although setting up Canvas may take a little longer than using, say, the Google Charts API  it's also much more flexible, and can even include animated charts.

Draw Something Using Canvas

Canvas is a vector graphics framework which works in most popular browsers today including Firefox, Opera and Safari, and does not require a plug-in like Flash does. Internet Explorer too can render Canvas code, at least with a little tweak you'll see further below. Canvas can be used to have a web page show 2D and 3D drawings, games, charts, applications, animations, and much more.

A longer canvas tutorial is available at http://developer.mozilla.org/en/docs/Canvas_tutorial (explaining how to draw rectangles, curves, imported images, and much more), but let's just see what you need to draw a simple line. First, create a file named index.html and open it with a plain text editor. Create a basic page like the following;

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; CHARSET=UTF-8" />
  <title>Drawing a line</title>
</head>
<body>
  <h1>Soon, a line will appear!</h1>
</body>
</html>

       

So far, that's all plain XHTML. Now somewhere in the <body> of the page, put the canvas tag:

Next, create a default.js file containing the following JavaScript, and put it in the same folder as index.html:
function main() {
    // grab the canvas
    var canvas = document.getElementById('picture');
    var ctx = canvas.getContext('2d');

    // set the color and line width
    ctx.strokeStyle = 'rgba(40,200,180,1)';
    ctx.lineWidth = 8;

    // draw a line
    ctx.beginPath();
    ctx.moveTo(40, 140);
    ctx.lineTo(240, 40);
    ctx.stroke();
}

That's not a lot of code—you're grabbing the canvas element using the ID you defined

Related Posts:
  • Small business SEO ROI calculation For the purposes of the ROI (Return on Investment) calculation for small business SEO, we'll make a few assumptions about the amount of traffic clicking through from Google (feel free to modify these if you think they are di… Read More
  • Title Tag SEO Tips Search engine spiders use these title tags as the main source for determining the page topic. Spiders or crawlers examine the title and then translate the topic of the page. This is one reason why it is always best to u… Read More
  • Free SEO Analysis Tools There are a myriad of free SEO tools available, and even many sites that list  these free tools (the compendium sites are generally supported by advertising,  and must therefore practice good SEO themselves to be s… Read More
  • SEO Tips on Conducting From the most high-level perspective, user researchis the science of observing and monitoring how we and our customers interact with everyday things such as websites or software or hardware, and to then draw conclusions a… Read More
  • How to traffic to your website Best seo practices How to promoting webpages Top seo tips top 10 e-commerce tips Additional seo tips Advanced seo tips Mobile seo tips How to traffic to your website 1. Article marketing. If you'd like… Read More
  • Seo Live gain /* Client-specific Styles */ #outlook a{padding:0;} /* Force Outlook to provide a "view in browser" button. */ body{width:100% !important;} .ReadMsgBody{width:100%;} .ExternalClass{width:100%;} /* Force Hotmail to display e… Read More
  • Top Tips For promoting web pages-seo Top Tips For promoting web pages-seo Search engine optimization - better information means better search engine optimization  involves tedious and complex set of activities neither it is a one-time task on the contra… Read More
  • SEO For Dynamically Generated Sites Now do the same thing on a dynamically generated site - anything with a php or jsp extension  is a good start. Dynamic seo 1 sitepoint.com: dynamic site seo tips and hints - sitepoint  dynamic sites require highly … Read More
  • SEO Pitfalls Google and other major search enginesurge you to avoid overly aggressive SEO practices when you build your site. Google has actually taken the trouble to spell out SEO practices it regards as naughty (the list can be foun… Read More
  • seo marketing plan Search engine marketing magazine seo , internet marketing, web increase visibility is a top  california seo company that delivers complete internet marketing strategies using advanced and innovative seo services and te… Read More
  • SEO Tips to get more Traffic SEO Tips to get more Traffic 1. Page titles should be as descriptive as possible about the content of the page and include main keyword target of the page. 2. Headers should include target keyword of the page. 3. Content… Read More
  • How to check broken Links Broken links are links that do not work, either because they have been miscoded or because the pages they point to don't exist (perhaps it has been moved).It's quite important to a search engine that none of the li… Read More
  • On Page SEO Techniques As stated above, on-page SEO has been the focus of techniques for a very long time. The first step for most on-page SEO will be to research a keyword list and decide which keywords the site should compete for. Keywords are t… Read More
  • how to get rank for a website google Everybody use google and it s by far the best and most popular search engine  on the internet have you ever asked yourself how does google decide which site.  How to get ranked number 1 on google - the website prom… Read More
  • Targeted Website Traffic Getting traffic online is very easy to do. The most important part about being successful online is getting your website noticed. You should be spending most of your days promoting your site over anything else in order to … Read More