Reader Level:
ARTICLE

Animated Yearly Chart Using HTML 5

On February 26, 2012 Articles | HTML 5
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.
  • 0
  • 0
  • 4085
Download Files:
 

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 the 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 new Web form
  • 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 are the media script.

d1.css scripting

body
{
   background: #7EC0EE;
    color: #fff;
    font: 300 100.1% "Helvetica Neue" , Helvetica, "Arial Unicode MS" , Arial, sans-serif;
}
#holder
{
    height: 442px;
    left: 42%;
    margin: -240px 0 0 -320px;
    position: absolute;
    top: 57%;
    width: 842px;
    font-size: x-large;
    background-color: #008000;
}
#duplicate {
    bottom: 0;
    font: 300 .7em "Helvetica Neue", Helvetica, ;
    position: absolute;
    right: 1em;
    text-align: right;
}
#duplicate d {
    color: #fff;
}


d2.css scripting.

body {
    background: #fff;
    color: #000;
    font: 100.1% "Comic Sans MS", Lucida, Verdana, sans-serif;
}
#holder {
    height: 480px;
    left: 50%;
    margin: 0 0 0 -320px;
    position: absolute;
    top: 0;
    width: 640px;
}
#duplicate {
    bottom: 0;
    font-size: .7em;
    position: absolute;
    right: 1em;
    text-align: right;
}

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.

Color(function ()
          {
            var r = Color("holder", 620, 250),
                    e = [],
                    clr = [],
                    months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
                    values = [],
                    now = 0,
                    month = r.text(310, 27, months[now]).attr({ fill: "#fff", stroke: "none", "font": '100 18px "Helvetica Neue", Helvetica, "Arial Unicode MS", Arial, sans-serif' }),
                    rightc = r.circle(364, 27, 10).attr({ fill: "#fff", stroke: "none" }),
                    right = r.path("M360,22l10,5 -10,5z").attr({ fill: "#000" }),
                    leftc = r.circle(256, 27, 10).attr({ fill: "#fff", stroke: "none" }),
                    left = r.path("M260,22l-10,5 10,5z").attr({ fill: "#000" }),
                    c = r.path("M0,0").attr({ fill: "none", "stroke-width": 4, "stroke-linecap": "round" }),
                    bg = r.path("M0,0").attr({ stroke: "none", opacity: .3 }),
                    dotsy = [];
            function randomPath(length, j)
              {
                var path = "",
                        x = 10,
                        y = 0;
                dotsy[j] = dotsy[j] || [];
                for (var i = 0; i < length; i++)
                   {
                    dotsy[j][i] = Math.round(Math.random() * 200);
                   if (i)
                    {
                        x += 20;
                        y = 240 - dotsy[j][i];
                        path += "," + [x, y];
                    }
                    else
                     {
                       path += "M" + [10, (y = 240 - dotsy[j][i])] + "R";
                    }
                }
                return path;
            }
            for (var i = 0; i < 12; i++)
             {
                values[i] = randomPath(30, i);
                clr[i] = Color.getColor(1);
             }
            c.attr({ path: values[0], stroke: clr[0] });
            bg.attr({ path: values[0] + "L590,250 10,250z", fill: clr[0] });
            var animation = function ()
             {
                var time = 500;
                if (now == 12)
                {
                    now = 0;
                }
                if (now == -1)
                {
                    now = 11;
                }
                var anim = Color.animation({ path: values[now], stroke: clr[now] }, time, "<>");
                c.animate(anim);
                bg.animateWith(c, anim, { path: values[now] + "L590,250 10,250z", fill: clr[now] }, time, "<>");
                month.attr({ text: months[now] });
            };
            var next = function ()
              {
                now++;
                animation();
              },
                    prev = function ()
                     {
                        now--;
                        animation();
                     };
            rightc.click(next);
            right.click(next);
            leftc.click(prev);
            left.click(prev);
        });

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.

<body>
<
center>
<
h2> Calender Chart </h2>
</center>
<
hr />
    <div id="holder">
    </div>
</body>

Step 5 : The complete code for the calendar application.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="calenderchart.aspx.cs" Inherits="calender._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="d1.css" media="screen">
    <link rel="stylesheet" href="d2.css" media="print">
    <style media="screen">
        #holder
        {
           height: 230px;
            margin: -115px 0 0 -310px;
            width: 620px;
        }
    </style>
    <script src="javascript.js"></script>
   
<script type="text/javascript">  
      
From Step 3 JavaScript copy from there and paste it here.
    </script
</head>
<
body>
<
center>
<
h2> Calender Chart </h2>
</center>
<
hr />
    <div id="holder">
    </div>
</body>
</
html>

Step 6 : Output Press F5

Note :
For the accurate output of HTML5 applications, you must have the Google Chrome browser in your PC. You
will see the calendar, or we can say the animated chart, is displayed as we run the application in the browser.

Month of January.


clnd1.gif

Month of March.

clnd2.gif

Here are the some useful resources.

Animated Key Strokes in HTML 5
Working With Growing Pie-chart Using HTML 5
Working With Pie Chart in HTML5
QC DATA PULLER using C#
Create Interactive Chart Using a HTML 5

Deepak Dwij

Patience creates a creativity in itself & time to achieve your desired goals. I m very much passionate about playing cricket !!!

  • 103rank
  • 723K readers
COMMENT USING

Trending up