Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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;
         m_chart.ChartAreas.Add(mainArea);

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

         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;
            }
            
         }
         m_chart.Series.Add(sr);

         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.

License

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

About the Author

Malphas1981
Software Developer
Italy Italy
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 13 Jul 2009
Article Copyright 2009 by Malphas1981
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid