Click here to Skip to main content
13,048,788 members (70,010 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.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebSamples._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <script type="text/javascript" src="Script/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="Script/jquery.json-1.3.min.js"></script>
    <form id="form1" runat="server">
    <script type="text/javascript">
       //retrive the URL of the WebService
       var WebServiceURL = "<%=Request.Url.GetLeftPart(UriPartial.Authority)+Request.ApplicationPath.ToString() %>/SampleWebService.asmx";

       //when DOM is ready...
       $(function() {
          //intercept the onchange event fire by element with "graphType" ID (SELECT)
          $("#graphType").change(function() {
             //get the attribute "value" of the OPTION element selected and pass it as parameter
             getChartImage($("option:selected", this).attr("value"));

       function getChartImage(type) {
          if (type < 0)

          //create the object for passing data to Web Service
          var dataPassed = new Object();
          dataPassed.iType = type;

          //call a Web service with jQuery
             type: "POST",
             contentType: "application/json; charset=utf-8",
             url: WebServiceURL + "/DrawChart",
             data: $.toJSON(dataPassed),
                  function(msg) {
                     var data = $.evalJSON(msg).d;
                     //set the "src" attribute of image
                     $("#ChartArea").attr("src", data);
                  function(XMLHttpRequest, textStatus, errorThrown) {
          <img id="ChartArea" />
          <select id="graphType">
             <option value="-1">Select type...</option>
             <option value="1">Sin (X)</option>
             <option value="2">Cos (X)</option>
             <option value="3">Tan (X)</option>

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
Web02 | 2.8.170713.1 | Last Updated 13 Jul 2009
Article Copyright 2009 by Malphas1981
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid