IMSL C# Chart
Programmer’s Guide
Web Server Application  Previous Page  Contents  Next Page

Web Server Application

An IMSL C# chart can be integrated into an ASP.NET application through the WebChart component. The WebChart class extends System.Web.UI.WebControls.Panel and can be added to an ASP.NET application like any other web control.

There are two sides to an ASP.NET application - the user interface and the code- behind class file. The user interface is often created visually with Visual Studio with the HTML code generated automatically. The code-behind class file is compiled into an assembly that is deployed with the web pages. The following example was generated using Visual Studio 2005. The method applies to other versions of Visual Studio though the code may be different in the details. The code-behind class file is written in C# like the other examples in this document.

The following code was automatically generated by Visual Studio by dragging a WebChart onto the page from the Toolbox containing web controls. The WebChart control can be added to the Toolbox by using the Add Items... dialog and browsing to the IMSL C# Library assembly, ImslCS.dll. Notice the reference to a WebChart object. This is the object that will be referenced from the code-behind class file.

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<%@ Register Assembly=”ImslCS” Namespace=”Imsl.Chart2D” TagPrefix=”cc1” %>
<!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>Untitled Page</title>
</head>
<body>
    <form id=”form1” runat=”server”>
    <div>
        <cc1:WebChart ID=”WebChart1” runat=”server” Height=”240px” Width=”240px”>
        </cc1:WebChart>
    </div>
    </form>
</body>
</html>

For this basic example, the chart is created in the Page_Load method of the code behind the web page. The Chart object is obtained from the WebChart and the chart is configured in a manner similar to the desktop form examples. All chart types and most functionality of the IMSL C# Library is available through the WebChart control.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Imsl.Chart2D;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Chart chart = WebChart1.Chart;
        AxisXY axis = new AxisXY(chart);
        Data data = new Data(axis, new double[] {5,7,4,1,8});
        data.DataType = ChartNode.DATA_TYPE_LINE | ChartNode.DATA_TYPE_MARKER;
        data.MarkerType = ChartNode.MARKER_TYPE_FILLED_SQUARE;
        data.MarkerColor = System.Drawing.Color.Red;
        data.LineColor = System.Drawing.Color.Green;
    }
}



©  Visual Numerics, Inc.  All rights reserved.  Previous Page  Contents  Next Page