PDA

View Full Version : ArgumentException when using WebChart from C# library



efimpechat
12-13-2007, 06:32 AM
Hi,
I'm using evaluation copy of C# library version 4.0. I didn't have problems to compile and run the charting examples using Windows Forms framework. I didn't find any examples of how to use charts in ASP.NET applications, so I created my own example based on the charting example in Evaluation Guide. It failes. Below is the code and the System.ArgumentException stack trace.

Please help me with this example, or point at the working example of charting in Web application.

Thank you,
efimpechat



=== Default.aspx ==============================
<%@ 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">
</cc1:WebChart>
</div>
</form>
</body>
</html>

=== Default.aspx.cs ==============================
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 System.Drawing;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) {
Imsl.Chart2D.Chart chart = WebChart1.Chart;
Imsl.Chart2D.AxisXY axis = new Imsl.Chart2D.AxisXY(chart);
double[] y = new double[] { 3, 8, 4, 5 };
Imsl.Chart2D.Bar bar = new Imsl.Chart2D.Bar(axis, y);
bar.FillColor = Color.Coral;
}
}
=================================
[ArgumentException: Parameter is not valid.]
System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) +422829
System.Drawing.Bitmap..ctor(Int32 width, Int32 height) +14
Imsl.Chart2D.WebChart.Render(HtmlTextWriter output) +220
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children) +130
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +24
System.Web.UI.HtmlControls.HtmlForm.RenderChildren (HtmlTextWriter writer) +59
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTex tWriter output) +68
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.HtmlControls.HtmlForm.RenderControl( HtmlTextWriter writer) +37
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children) +130
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +24
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1896

================================

efimpechat
12-13-2007, 06:56 AM
I found the problem. I just needed to specify width and height for the chart object, like in the code below (compare with my original post). I'm glad it works, but I don't think application should crash when dimensions are not specified, it should assume reasonable defaults, or at least throw an own, problem specific, exception.


<cc1:WebChart ID="WebChart1" runat="server" Height="605px" Width="953px">
</cc1:WebChart>

ed
12-13-2007, 12:11 PM
Glad you found the issue. The documentation on WebChart is admittedly a bit scarce. For the next release, we will be including a Chart Programmer's Guide with the IMSL C# product that includes many more examples, including an ASP.NET example.