Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 695191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:56:02+00:00 2026-05-14T02:56:02+00:00

I’m trying to create a .net charting control completely in the code behind and

  • 0

I’m trying to create a .net charting control completely in the code behind and insert that chart at a specific location on the web page.

Here is my html page:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="chart"></div>
    </form>
</body>
</html>

Here is the code behind:

using System;
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
      //SET UP THE DATA TO PLOT  
        double[] yVal = { 80, 20 };
        string[] xName = { "Pass", "Fail" };

      //CREATE THE CHART
        Chart Chart1 = new Chart();

      //BIND THE DATA TO THE CHART
        Chart1.Series.Add(new Series());
        Chart1.Series[0].Points.DataBindXY(xName, yVal);

      //SET THE CHART TYPE TO BE PIE
        Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;
        Chart1.Series[0]["PieLabelStyle"] = "Outside";
        Chart1.Series[0]["PieStartAngle"] = "-90";

      //SET THE COLOR PALETTE FOR THE CHART TO BE A PRESET OF NONE 
      //DEFINE OUR OWN COLOR PALETTE FOR THE CHART 
        Chart1.Palette = System.Web.UI.DataVisualization.Charting.ChartColorPalette.None;
        Chart1.PaletteCustomColors = new Color[] { Color.Blue, Color.Red };

      //SET THE IMAGE OUTPUT TYPE TO BE JPEG
        Chart1.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageType.Jpeg;

      //ADD A PLACE HOLDER CHART AREA TO THE CHART
      //SET THE CHART AREA TO BE 3D
        Chart1.ChartAreas.Add(new ChartArea());
        Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;

      //ADD A PLACE HOLDER LEGEND TO THE CHART
      //DISABLE THE LEGEND
        Chart1.Legends.Add(new Legend());
        Chart1.Legends[0].Enabled = false;
    }
}

I want to render the charting control inside the div with id=”chart”

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:56:03+00:00Added an answer on May 14, 2026 at 2:56 am

    Assuming you installed the charting framework without any hitches:-

    View:-

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_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">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="chart"></div>
            <asp:Chart id="Chart1" runat="server"/>
        </form>
    </body>
    </html>
    

    Codebehind:-

    using System;
    using System.Drawing;
    using System.Web.UI.DataVisualization.Charting;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          //SET UP THE DATA TO PLOT  
            double[] yVal = { 80, 20 };
            string[] xName = { "Pass", "Fail" };
    
          //CREATE THE CHART
            // Don't need to create the chart because it's a control!
    
          //BIND THE DATA TO THE CHART
            Chart1.Series.Add(new Series());
            Chart1.Series[0].Points.DataBindXY(xName, yVal);
    
          //SET THE CHART TYPE TO BE PIE
            Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;
            Chart1.Series[0]["PieLabelStyle"] = "Outside";
            Chart1.Series[0]["PieStartAngle"] = "-90";
    
          //SET THE COLOR PALETTE FOR THE CHART TO BE A PRESET OF NONE 
          //DEFINE OUR OWN COLOR PALETTE FOR THE CHART 
            Chart1.Palette = System.Web.UI.DataVisualization.Charting.ChartColorPalette.None;
            Chart1.PaletteCustomColors = new Color[] { Color.Blue, Color.Red };
    
          //SET THE IMAGE OUTPUT TYPE TO BE JPEG
            Chart1.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageType.Jpeg;
    
          //ADD A PLACE HOLDER CHART AREA TO THE CHART
          //SET THE CHART AREA TO BE 3D
            Chart1.ChartAreas.Add(new ChartArea());
            Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
    
          //ADD A PLACE HOLDER LEGEND TO THE CHART
          //DISABLE THE LEGEND
            Chart1.Legends.Add(new Legend());
            Chart1.Legends[0].Enabled = false;
        }
    }
    

    Check out http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer (Edited) Both gcc and MSVC allow 'anonymous' structs/unions, which might… May 14, 2026 at 10:13 pm
  • Editorial Team
    Editorial Team added an answer It looks like Generics might be useful for what you're… May 14, 2026 at 10:13 pm
  • Editorial Team
    Editorial Team added an answer string value = myDictionary.First(v => StringComparer.Create(CultureInfo.CurrentCulture,true) .Compare(v.Key,"AAA") == 0) .Key May 14, 2026 at 10:12 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.