3D Chart In ASP.Net Programming


As we know charts are a very popular and important tool in ASP.Net technology. A chart is nothing but a pictorial or graphical representation of data. There are two coordinates present in a chart, one is the X axis and the other is the Y axis. In the chart we represent the data using the bar lines, bar charts or the slice of the pie charts. Using the chart control we can represent the data and also we can compare the data from the various charts like compare the previous year's revenue and the current year's revenue. There are many types of charts like bar charts, line charts, slice charts, column charts, combo charts and so on.

This article shows how to make charts in ASP.NET and how to represent the data. So first I will show how to make a simple chart in ASP.NET with C#.

Procedure for Simple Chart

Step 1

Open Visual Studio, go to the File menu, go to the new website and add an "ASP.NET Empty Web Site".

Step 2

Now go to the Solution Explorer, right-click on the website and go to the add new item and then add a new form.

Step 3

Now go the toolbar, right-click on the standard, click on choose item in the .Net Framework Component. We will see two chart options; click on them and save.

Step 4

Now in the toolbar go to the data. Here you will see a chart option. You can drag and drop the chart from the toolbar to your page.

Step 5

When you drag and drop a chart control onto your page then there is an entry automatically generated in your web.config file.

  1. <appSettings>  
  2.     <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />  
  3.   </appSettings>  
Step 6

There is also one more tag generated in the web.config file named httpHandlers in the code like this.
  1. <httpHandlers>  
  2.       <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  
  3.         validate="false" />  
  4.     </httpHandlers>  
Step 7

Another tag is also added, that tag is known as the control-definition tag.
  1. <controls>    
  2.         <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"    
  3.           assembly="System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />    
  4.       </controls> 
Step 8

In the web.config finally one one more tags are known as the Data Visualization assembly.
  1. <assemblies>    
  2.         <add assembly="System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>    
  3.       </assemblies>  
These four basic tags will be present in your web.config file. Then in your Default.aspx page you will see a normal chart.

Step 9

Right-click on your chart and go to the property. In the property window go to the data source and select a data source and add that data source.

Step 10

After adding the data source successfully, go to the chart properties again and click on the series, explore the series and you will see a window like this.

Step 11

Now in the series, go to the data source and make the Xvalue member as you need to. Here I created a Xvalue member name and Yvalue member age depending on my needs. You can choose as you desire. If we want to provide a name for the X and Y axis in the chart then go again to the property window and click on the chart area; here you will see an Axes property.

In the axes property now click on the axes collection and open the title in the X Axes. I select the title Name and in the Y axes I select the title Age.

Step 12

Now when you run your application you will see the output like this.

As I said there are many types of charts available in ASP.NET, like Bar Chart, Line Chart, Column Chart, Pie Chart and so on. So here I will show you those types.

Types of Charts

If you want to see all the types of charts available in ASP.Net then it is not very tough, it is easy. Just go to your chart and right-click on it. Here you will see a list of all the charts available in ASP.Net.

3D Chart 

Now we will discuss how to make 3D charts in ASP.NET.

First go to Visual Studio, go to the file, website and add a new website, then drag and drop a normal chart onto your aspx page. When you do that there are some tags added to your web.config file as I explained above. Then only in our aspx page we have a chart area tag. In the chart area tag we enable 3D (3D=true). We can also do this using the wizard simply. Right-click on the chart and go to its property, go into the charts area property, then go to 3D chart settings and make the Enable 3D true, by default it is false.

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExamChart.aspx.cs" Inherits="ExamChart" %>  
  3. <%@ Register Assembly="System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  
  4.     Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  8. <html xmlns="http://www.w3.org/1999/xhtml">  
  9. <head runat="server">  
  10.     <title></title>  
  11. </head>  
  12. <body>  
  13.     <form id="form1" runat="server">  
  14.     <div>  
  15.          <asp:Chart ID="ScoreChart" Width="600" Height="320" runat="server"   
  16.             BackColor="Silver" BackGradientStyle="LeftRight" BorderlineWidth="2"   
  17.             TabIndex="2">  
  18.       <Titles>  
  19.       <asp:Title Text="Runs" />  
  20.       </Titles>  
  21.         <Series>  
  22.           <asp:Series Name="RunSeries" ChartType="Column">  
  24.           </asp:Series>  
  25.         </Series>  
  26.         <ChartAreas>  
  27.           <asp:ChartArea Name="ChartArea1">  
  28.           <Area3DStyle Enable3D="true"  WallWidth="10" />  
  29.               <AxisY Title="Runs">  
  30.               </AxisY>  
  31.               <AxisX Title="Players Name">  
  32.               </AxisX>  
  33. <Area3DStyle Enable3D="True" WallWidth="10"></Area3DStyle>  
  34.           </asp:ChartArea>  
  35.         </ChartAreas>  
  36.       </asp:Chart>  
  38.     </div>  
  39.     </form>  
  40. </body>  
  41. </html>  
We make properties for this form so add a class file and write this code in the class file.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  6. public class run  
  7. {  
  8.     public string Name { getset; }  
  9.     public int Point { getset; }  
  10.     public string PictureUrl { getset; }   
  11. }  
After this we simply make a Bind method and call it on the page load event. The code for the Bind Method is the following:
  1. sing System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Web.UI.DataVisualization.Charting;  
  9. public partial class ExamChart : System.Web.UI.Page  
  10. {  
  11.     protected void Page_Load(object sender, EventArgs e)  
  12.     {  
  13.         if (!Page.IsPostBack)  
  14.         {  
  16.             BindData();  
  18.         }  
  20.     }  
  22.     private void BindData()  
  23.     {  
  25.         var runs = new List<run>()  
  26.             {  
  27.                 new run() { Name = "Sachin", Point = 200, PictureUrl="Images/sachin.jpg" },   
  28.                 new run() { Name = "Dhoni", Point = 32, PictureUrl="Images/dhoni.jpg" },   
  29.                 new run() { Name = "Yuvraj", Point = 78, PictureUrl="Images/yuvraj.jpg" },   
  30.                  new run() { Name = "Kohli", Point = 50, PictureUrl="Images/kohli.jpg" },   
  31.                 new run() { Name = "Raina", Point = 32, PictureUrl="Images/raina.jpg" },   
  32.                 new run() { Name = "Dhawan", Point = 155, PictureUrl="Images/dhawan.jpg" },   
  33.                 new run() { Name = "Rahane", Point = 22, PictureUrl="Images/rahane.jpg" }  
  34.             };  
  36.         var series = ScoreChart.Series["RunSeries"];  
  38.         foreach (var exam in runs)  
  39.         {  
  41.             var point = new DataPoint();  
  42.             point.SetValueXY(exam.Name, exam.Point);  
  44.             point.MarkerImage = exam.PictureUrl;  
  46.             point.Label = exam.Point.ToString();  
  47.             series.Points.Add(point);  
  48.         }  
  50.         ScoreChart.DataSource = runs;  
  51.         ScoreChart.DataBind();  
  52.     }  
  53. }  
Now when you run your application you will see a 3D chart like this.

Properties of 3D Chart 

As you know, enable the 3D and then we can create a 3D chart, it is a Boolean type so it may be true or may be false but by default it always false. The angle is available for the 3D chart. In ASP.NET it is between -90 degrees to 90 degrees, if you choose -90 then it takes you fully below and if you choose 90 then it takes you fully above. There is a property known as the "Is clustered" property that is also a Boolean value that provides the benefits of using the many charts that are the same type and the same nature for making the the chart view more effective. LightStyle is an option for Realistic, Simplistic, or None based on which lighting you wish to have on your chart. If you want to show the percentage as a 3D chart then there will be the three axis X,Y and Z in the x axis we have marks for the axis totals Marks and the Z axis represents the percentage so we can also represent the percentage from the chart.


Charts play a very good role to represent a report or data. As we know charts are a pictorial representation of data and everyone is familiar with them. A picture is more powerful than a thousand of words. Charts make comprehenssion very easy compared to any other method. 3D charts look very effective and beautiful and they have more clarity and effectiveness compared with simple charts. I hope using this article you can learn both types of charts, simple charts and 3D effect charts.


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now