Animated Yearly Chart Using HTML 5

Introduction

 
In this article, we are going to have a very interesting section related to designing. In this, the calendar (or we can say the animated chart) is displayed as we run the application in the browser.
 
Here we will use some JavaScript and some styles along with HTML code. Just go through the steps to see how to create this application. Let's see how the calendar application can be created. To do so use the following steps.
 
Step 1 : Open a HTML editor or Visual Studio.
 
sd.gif
 
Open File menu ->select new ->Choose Website then.
 
0000.jpg
 
This is where we will create am HTML5 application.
  • Go to Solution Explorer
  • Right-click on the Application name
  • Select Add-->add new item
  • Now in the window that opens, select an HTML page or a new Webform
  • Rename it to calenderchart.aspx
clnd.gif
 
Step 2: In this section, we will create the style for the media and create the .css on the media screen. Put the given script in the Head section of the HTML or between the <head>--</head> tags.
 
Here two CSS files are used for design purposes; one is for the section div, named d1.css and the other d2.css for the whole body of the web page as added in the calendar.rar file. Here is the media script.
 
d1.css scripting
  1. body  
  2. {  
  3.    background#7EC0EE;  
  4.     color#fff;  
  5.     font300 100.1% "Helvetica Neue" , Helvetica"Arial Unicode MS" , Arialsans-serif;  
  6. }  
  7. #holder  
  8. {  
  9.     height442px;  
  10.     left: 42%;  
  11.     margin-240px 0 0 -320px;  
  12.     positionabsolute;  
  13.     top: 57%;  
  14.     width842px;  
  15.     font-sizex-large;  
  16.     background-color#008000;  
  17. }  
  18. #duplicate {  
  19.     bottom: 0;  
  20.     font300 .7em "Helvetica Neue"Helvetica, ;  
  21.     positionabsolute;  
  22.     right: 1em;  
  23.     text-alignright;  
  24. }  
  25. #duplicate d {  
  26.     color#fff;  
d2.css scripting
  1. body {  
  2.     background#fff;  
  3.     color#000;  
  4.     font100.1% "Comic Sans MS", Lucida, Verdanasans-serif;  
  5. }  
  6. #holder {  
  7.     height480px;  
  8.     left: 50%;  
  9.     margin0 0 0 -320px;  
  10.     positionabsolute;  
  11.     top: 0;  
  12.     width640px;  
  13. }  
  14. #duplicate {  
  15.     bottom: 0;  
  16.     font-size: .7em;  
  17.     positionabsolute;  
  18.     right: 1em;  
  19.     text-alignright;  
Step 3 : In this part we need to work on some JavaScript. For fully understanding how the JavaScript works, download the attached .rar file and run the calendar application.
 
The whole JavaScript looks as in the following.
  1. Color(function ()  
  2.           {  
  3.             var r = Color("holder", 620, 250),  
  4.                     e = [],  
  5.                     clr = [],  
  6.                     months = ["January""February""March""April""May""June""July""August""September""October""November""December"],  
  7.                     values = [],  
  8.                     now = 0,  
  9.                     month = r.text(310, 27, months[now]).attr({ fill: "#fff", stroke: "none""font"'100 18px "Helvetica Neue", Helvetica, "Arial Unicode MS", Arial, sans-serif' }),  
  10.                     rightc = r.circle(364, 27, 10).attr({ fill: "#fff", stroke: "none" }),  
  11.                     right = r.path("M360,22l10,5 -10,5z").attr({ fill: "#000" }),  
  12.                     leftc = r.circle(256, 27, 10).attr({ fill: "#fff", stroke: "none" }),  
  13.                     left = r.path("M260,22l-10,5 10,5z").attr({ fill: "#000" }),  
  14.                     c = r.path("M0,0").attr({ fill: "none""stroke-width": 4, "stroke-linecap""round" }),  
  15.                     bg = r.path("M0,0").attr({ stroke: "none", opacity: .3 }),  
  16.                     dotsy = [];  
  17.             function randomPath(length, j)  
  18.               {  
  19.                 var path = "",  
  20.                         x = 10,  
  21.                         y = 0;  
  22.                 dotsy[j] = dotsy[j] || [];  
  23.                 for (var i = 0; i < length; i++)  
  24.                    {  
  25.                     dotsy[j][i] = Math.round(Math.random() * 200);  
  26.                    if (i)  
  27.                     {  
  28.                         x += 20;  
  29.                         y = 240 - dotsy[j][i];  
  30.                         path += "," + [x, y];  
  31.                     }  
  32.                     else  
  33.                      {  
  34.                        path += "M" + [10, (y = 240 - dotsy[j][i])] + "R";  
  35.                     }  
  36.                 }  
  37.                 return path;  
  38.             }  
  39.             for (var i = 0; i < 12; i++)  
  40.              {  
  41.                 values[i] = randomPath(30, i);  
  42.                 clr[i] = Color.getColor(1);  
  43.              }  
  44.             c.attr({ path: values[0], stroke: clr[0] });  
  45.             bg.attr({ path: values[0] + "L590,250 10,250z", fill: clr[0] });  
  46.             var animation = function ()  
  47.              {  
  48.                 var time = 500;  
  49.                 if (now == 12)  
  50.                 {  
  51.                     now = 0;  
  52.                 }  
  53.                 if (now == -1)  
  54.                 {  
  55.                     now = 11;  
  56.                 }  
  57.                 var anim = Color.animation({ path: values[now], stroke: clr[now] }, time, "<>");  
  58.                 c.animate(anim);  
  59.                 bg.animateWith(c, anim, { path: values[now] + "L590,250 10,250z", fill: clr[now] }, time, "<>");  
  60.                 month.attr({ text: months[now] });  
  61.             };  
  62.             var next = function ()  
  63.               {  
  64.                 now++;  
  65.                 animation();  
  66.               },  
  67.                     prev = function ()  
  68.                      {  
  69.                         now--;  
  70.                         animation();  
  71.                      };  
  72.             rightc.click(next);  
  73.             right.click(next);  
  74.             leftc.click(prev);  
  75.             left.click(prev);  
  76.         }); 
Step 4: In this section we are going to become familiar with the body part of HTML scripting. Replace this script from the body section of the calenderchart.aspx page. Here we pass a #holder in the div id that is defined in the d1.css file.
  1. <body>  
  2. <center>  
  3. <h2> Calender Chart </h2>  
  4. </center>  
  5. <hr />  
  6.     <div id="holder">  
  7.     </div>  
  8. </body> 
Step 5: The complete code for the calendar application.
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="calenderchart.aspx.cs" Inherits="calender._Default" %>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head runat="server">  
  5.     <meta charset="utf-8">  
  6.     <title></title>  
  7.     <link rel="stylesheet" href="d1.css" media="screen">  
  8.     <link rel="stylesheet" href="d2.css" media="print">  
  9.     <style media="screen">  
  10.         #holder  
  11.         {  
  12.            height: 230px;  
  13.             margin: -115px 0 0 -310px;  
  14.             width: 620px;  
  15.         }  
  16.     </style>  
  17.     <script src="javascript.js"></script>  
  18.     <script type="text/javascript">    
  19.       From Step 3 JavaScript copy from there and paste it here.  
  20.     </script  
  21. </head>  
  22. <body>  
  23. <center>  
  24. <h2> Calender Chart </h2>  
  25. </center>  
  26. <hr />  
  27.     <div id="holder">  
  28.     </div>  
  29. </body>  
  30. </html> 
Step 6: Output Press F5
 
Note: For the accurate output of HTML5 applications, you must have the Google Chrome browser on your PC. You will see the calendar, or we can say the animated chart, is displayed as we run the application in the browser.
 
The month of January.
 
clnd1.gif
 
The month of March.
 
clnd2.gif
 
Here are some useful resources.