Click here to Skip to main content
11,434,799 members (45,735 online)
Click here to Skip to main content
Add your own
alternative version

Improve ASP.NET Chart with jQuery

, 13 Jul 2009 CPOL
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.Web;
using System.Web.Services;
using System.Web.UI.DataVisualization.Charting;
using System.IO;

namespace WebSamples
   /// <summary>
   /// Summary description for SampleWebService
   /// </summary>
   [WebService(Namespace = "")]
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   public class SampleWebService : System.Web.Services.WebService

      public string HelloWorld()
         return "Hello World";

      /// <summary>
      /// Create a chart image and return image file name
      /// </summary>
      ///<param name="iType"> 
      ///Type of the chart to draw: 1=Sin(x) 2=Cos(x) 3=Tan(x)
      public String DrawChart(Int32 iType){

         //class that creates the Chart object
         RuntimeChart runChart = new RuntimeChart();
         Chart m_chart = runChart.makeChart(iType);

         String tempFileName = String.Format("TempChartImage/Chart_{0}.png", System.Guid.NewGuid().ToString());

         tempFileName = Context.Server.MapPath(tempFileName);

         String strImageSrc = @"TempChartImage/" + Path.GetFileName(tempFileName);

         // set callback when item was removed from cache
         ChartImageDestructor cid = new ChartImageDestructor(tempFileName);
         System.Web.Caching.CacheItemRemovedCallback onRemove = new System.Web.Caching.CacheItemRemovedCallback(cid.RemovedCallback);

         //insert filename into cache
         HttpContext.Current.Cache.Add(tempFileName, cid, null,

         return strImageSrc;

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150428.2 | Last Updated 13 Jul 2009
Article Copyright 2009 by Malphas1981
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid