Click here to Skip to main content
13,089,943 members (43,531 online)
Click here to Skip to main content


68 bookmarked
Posted 13 Jul 2009

Improve ASP.NET Chart with jQuery

, 13 Jul 2009
A simple example of how to use the ASP.NET charting control with jQuery.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Collections;
using System.Data;

namespace WebSamples
   public class RuntimeChart{
      private Chart m_chart;

      public RuntimeChart() {
         m_chart = new Chart();

      public Chart makeChart(Int32 iType){
         //Chart setting 
         m_chart.Height = Unit.Pixel(200);
         m_chart.Width = Unit.Pixel(400);
         m_chart.BorderlineColor = Color.Black;
         m_chart.BorderlineDashStyle = ChartDashStyle.Solid;
         m_chart.BorderlineWidth = 2;
         m_chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;

         //Chart Area
         ChartArea mainArea = new ChartArea();
         mainArea.Name = "mainArea";
         mainArea.BackColor = Color.FromArgb(255, 255, 192);
         mainArea.BackGradientStyle = GradientStyle.TopBottom;
         mainArea.BorderDashStyle = ChartDashStyle.Solid;

         Legend mainLegend = new Legend();
         mainLegend.Name = "mainLegend";
         mainLegend.DockedToChartArea = "mainArea";
         mainLegend.Docking = Docking.Top;
         mainLegend.HeaderSeparator = LegendSeparatorStyle.Line;
         mainLegend.IsDockedInsideChartArea = false;

         Series sr = new Series();
         sr.ChartArea = "mainArea";
         sr.Legend = "mainLegend";
         sr.ChartType = SeriesChartType.Spline;
         sr.Name = "Series1";

         //generate some point for the chart
         for (Int32 i = 0; i < 10; i++)
            Double x = (Double)i;

            //value of the y depend on parameter iType
            switch (iType) {
               case 1: {
                  sr.Points.AddXY(x, Math.Sin(x));
               } break;
               case 2:{
                  sr.Points.AddXY(x, Math.Cos(x));
                  } break;
               case 3:{
                  sr.Points.AddXY(x, Math.Tan(x));
                  } break;

         return m_chart;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Italy Italy
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170813.1 | Last Updated 13 Jul 2009
Article Copyright 2009 by Malphas1981
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid