OWC10 : problems with data binding to an Ado recordset

G

Gianni

Could someone help me to understand why this script
doesn't work well?
As you can see I've a recordset with 3 series, but only
two of them appear properly on my chart: it seems the
first 3 records doesn't bound to chart.
Thank you very much! ;-)
Ciao, Gianni

<%@language="vbscript" lcid="1040"%>
<% Option Explicit %>
<%

dim rsch
set rsch = getrs()

Dim ChartSpace, c, objChart
Set ChartSpace = server.CreateObject
("OWC10.ChartSpace")
ChartSpace.clear
Set c = ChartSpace.Constants

set ChartSpace.DataSource = rsch
ChartSpace.Charts(0).HasLegend = True
ChartSpace.Charts(0).HasTitle = True
ChartSpace.Charts(0).Title.Caption = "Andamento.."
ChartSpace.Charts(0).Type =
c.chChartTypeLineMarkers
ChartSpace.DisplayFieldButtons = false


ChartSpace.SetData c.chDimCategories,0, "data"
ChartSpace.SetData c.chDimSeriesNames,0, "titolo"
ChartSpace.SetData c.chDimValues, 0, "valore"

Response.Expires = 0
Response.Buffer = True
Response.Clear
Response.ContentType = "image/gif"
Response.BinaryWrite ChartSpace.GetPicture("gif",
564,300)
Response.Flush

%>

<%
Function getrs()
dim rsStato
const adVarChar = 200
set rsStato = server.CreateObject
("ADODB.Recordset")
rsStato.CursorType = 3
rsStato.CursorLocation = 3
rsStato.Fields.Append "titolo", adVarChar,
10
rsStato.Fields.Append "data", 7, 8
rsStato.Fields.Append "valore", 6, 8

rsStato_Open
rsStato.AddNew
rsStato("titolo") = "pippo"
rsStato("data") = "01/01/03"
rsStato("valore") = 6.55

rsStato.AddNew
rsStato("titolo") = "pippo"
rsStato("data") = "31/01/03"
rsStato("valore") = 6.2

rsStato.AddNew
rsStato("titolo") = "pippo"
rsStato("data") = "28/02/03"
rsStato("valore") = 6.4

rsStato.AddNew
rsStato("titolo") = "pippo"
rsStato("data") = "31/03/03"
rsStato("valore") = 6.12

rsStato.AddNew
rsStato("titolo") = "pluto"
rsStato("data") = "01/01/03"
rsStato("valore") = 5.55

rsStato.AddNew
rsStato("titolo") = "pluto"
rsStato("data") = "31/01/03"
rsStato("valore") = 5.6


rsStato.AddNew
rsStato("titolo") = "pluto"
rsStato("data") = "28/02/03"
rsStato("valore") = 5.65

rsStato.AddNew
rsStato("titolo") = "pluto"
rsStato("data") = "31/03/03"
rsStato("valore") = 5.72

rsStato.AddNew
rsStato("titolo") = "paperino"
rsStato("data") = "01/01/03"
rsStato("valore") = 6

rsStato.AddNew
rsStato("titolo") = "paperino"
rsStato("data") = "31/01/03"
rsStato("valore") = 6


rsStato.AddNew
rsStato("titolo") = "paperino"
rsStato("data") = "28/02/03"
rsStato("valore") = 5.7

rsStato.AddNew
rsStato("titolo") = "paperino"
rsStato("data") = "31/03/03"
rsStato("valore") = 5.75


rsStato.Update
rsStato.MoveFirst
set getrs = rsStato
end function
%>
 
T

Thao Moua [ms]

Several things you can do to figure this out. See if the
legend displays all the series name from "tilolo" and
very the returned data from the three fields "tilolo,
data, and valore" are valid.

If possible can I see your data and code? Thanks.

Thao Moua
OWC Webchart Support
 
G

Gianni

The legned displays all series from "titolo" and datapoint
are returned correctly, except the first one.
You can see my code down this page.
I create my recordset 'on the fly' by the 'getrs' function.
The recordset will appear like this:
data titolo valore
titolo:[pippo] data:[01/01/2003] valore:[6,55]
titolo:[pippo] data:[31/01/2003] valore:[6,2]
titolo:[pippo] data:[28/02/2003] valore:[6,4]
titolo:[pippo] data:[31/03/2003] valore:[6,12]
titolo:[pluto] data:[01/01/2003] valore:[5,55]
titolo:[pluto] data:[31/01/2003] valore:[5,6]
titolo:[pluto] data:[28/02/2003] valore:[5,65]
titolo:[pluto] data:[31/03/2003] valore:[5,72]
titolo:[paperino] data:[01/01/2003] valore:[6]
titolo:[paperino] data:[31/01/2003] valore:[6]
titolo:[paperino] data:[28/02/2003] valore:[5,7]
titolo:[paperino] data:[31/03/2003] valore:[5,75]
thank you very much
G.
 
T

Thao Moua [ms]

I looked at your code and you need to add some few
properies. See below.
------------
Dim rsch
Set rsch = getrs()

Dim ChartSpace As OWC10.ChartSpace
Dim c
Dim objChart As OWC10.ChChart

Set ChartSpace = CreateObject("OWC10.ChartSpace")
ChartSpace.Clear
Set c = ChartSpace.Constants

Set ChartSpace.DataSource = rsch
ChartSpace.DisplayFieldButtons = False
ChartSpace.Charts(0).Type = c.chChartTypeLineMarkers
'the GroupingType will either auto/manual/none group
your category data
ChartSpace.Charts(0).Axes
(c.chAxisPositionCategory).GroupingType =
c.chAxisGroupingNone

ChartSpace.SetData c.chDimSeriesNames, 0, "titolo"
ChartSpace.SetData c.chDimCategories, 0, "data"
ChartSpace.SetData c.chDimValues, 0, "valore"

ChartSpace.Charts(0).HasLegend = True
ChartSpace.Charts(0).HasTitle = True
ChartSpace.Charts(0).Title.Caption = "Andamento.."
----------
You are right about one of the series not displaying all
the points. I tried moving your data around and it
seemed the very first record set is being droppped. This
looks like a bug in Chart. I'll post this bug for you.
Thanks.

A work around for this is to create literal array and
pass it into chart like this.

---------
Dim series(3), category(5), values(5), Chart, x, Constants

series(0) = "series-0": series(1) = "series-1": series(2)
= "series-2"

category(0) = "aa": category(1) = "bb": category(2)
= "cc": category(3) = "dd": category(4) = "ee"

Set webChart = ChartSpace
webChart.Clear

Set Constants = webChart.Constants

webChart.Charts.Add 'create a chart
webChart.HasChartSpaceLegend = True
webChart.Charts(0).SeriesCollection.Add 'add three series
webChart.Charts(0).SeriesCollection.Add
webChart.Charts(0).SeriesCollection.Add

Set Chart = webChart.Charts(0)

Chart.SetData Constants.chDimCategories,
Constants.chDataLiteral, category 'set the category names
Chart.SetData Constants.chdimseriesname,
Constants.chDataLiteral, series 'set the series
names

values(0) = 10: values(1) = 20: values(2) = 30: values(3)
= 40: values(4) = 50
Chart.SeriesCollection(0).SetData Constants.chDimValues,
Constants.chDataLiteral, values

values(0) = 90: values(1) = 80: values(2) = 70: values(3)
= 60: values(4) = 50
Chart.SeriesCollection(1).SetData Constants.chDimValues,
Constants.chDataLiteral, values

values(0) = 25: values(1) = 45: values(2) = 65: values(3)
= 35: values(4) = 15
Chart.SeriesCollection(2).SetData Constants.chDimValues,
Constants.chDataLiteral, values
----------

Thao Moua
OWC Webchart Support
-----Original Message-----
The legned displays all series from "titolo" and datapoint
are returned correctly, except the first one.
You can see my code down this page.
I create my recordset 'on the fly' by the 'getrs' function.
The recordset will appear like this:
data titolo valore
titolo:[pippo] data:[01/01/2003] valore:[6,55]
titolo:[pippo] data:[31/01/2003] valore:[6,2]
titolo:[pippo] data:[28/02/2003] valore:[6,4]
titolo:[pippo] data:[31/03/2003] valore:[6,12]
titolo:[pluto] data:[01/01/2003] valore:[5,55]
titolo:[pluto] data:[31/01/2003] valore:[5,6]
titolo:[pluto] data:[28/02/2003] valore:[5,65]
titolo:[pluto] data:[31/03/2003] valore:[5,72]
titolo:[paperino] data:[01/01/2003] valore:[6]
titolo:[paperino] data:[31/01/2003] valore:[6]
titolo:[paperino] data:[28/02/2003] valore:[5,7]
titolo:[paperino] data:[31/03/2003] valore:[5,75]
thank you very much
G.
-----Original Message-----
Several things you can do to figure this out. See if the
legend displays all the series name from "tilolo" and
very the returned data from the three fields "tilolo,
data, and valore" are valid.

If possible can I see your data and code? Thanks.

Thao Moua
OWC Webchart Support
.
.
 
G

Gianni

Thanks a lot!
can you send me an e-mail when bug will be resolved?
if you can't thanks a lot anyway
Gianni
-----Original Message-----
I looked at your code and you need to add some few
properies. See below.
------------
Dim rsch
Set rsch = getrs()

Dim ChartSpace As OWC10.ChartSpace
Dim c
Dim objChart As OWC10.ChChart

Set ChartSpace = CreateObject("OWC10.ChartSpace")
ChartSpace.Clear
Set c = ChartSpace.Constants

Set ChartSpace.DataSource = rsch
ChartSpace.DisplayFieldButtons = False
ChartSpace.Charts(0).Type = c.chChartTypeLineMarkers
'the GroupingType will either auto/manual/none group
your category data
ChartSpace.Charts(0).Axes
(c.chAxisPositionCategory).GroupingType =
c.chAxisGroupingNone

ChartSpace.SetData c.chDimSeriesNames, 0, "titolo"
ChartSpace.SetData c.chDimCategories, 0, "data"
ChartSpace.SetData c.chDimValues, 0, "valore"

ChartSpace.Charts(0).HasLegend = True
ChartSpace.Charts(0).HasTitle = True
ChartSpace.Charts(0).Title.Caption = "Andamento.."
----------
You are right about one of the series not displaying all
the points. I tried moving your data around and it
seemed the very first record set is being droppped. This
looks like a bug in Chart. I'll post this bug for you.
Thanks.

A work around for this is to create literal array and
pass it into chart like this.

---------
Dim series(3), category(5), values(5), Chart, x, Constants

series(0) = "series-0": series(1) = "series-1": series(2)
= "series-2"

category(0) = "aa": category(1) = "bb": category(2)
= "cc": category(3) = "dd": category(4) = "ee"

Set webChart = ChartSpace
webChart.Clear

Set Constants = webChart.Constants

webChart.Charts.Add 'create a chart
webChart.HasChartSpaceLegend = True
webChart.Charts(0).SeriesCollection.Add 'add three series
webChart.Charts(0).SeriesCollection.Add
webChart.Charts(0).SeriesCollection.Add

Set Chart = webChart.Charts(0)

Chart.SetData Constants.chDimCategories,
Constants.chDataLiteral, category 'set the category names
Chart.SetData Constants.chdimseriesname,
Constants.chDataLiteral, series 'set the series
names

values(0) = 10: values(1) = 20: values(2) = 30: values(3)
= 40: values(4) = 50
Chart.SeriesCollection(0).SetData Constants.chDimValues,
Constants.chDataLiteral, values

values(0) = 90: values(1) = 80: values(2) = 70: values(3)
= 60: values(4) = 50
Chart.SeriesCollection(1).SetData Constants.chDimValues,
Constants.chDataLiteral, values

values(0) = 25: values(1) = 45: values(2) = 65: values(3)
= 35: values(4) = 15
Chart.SeriesCollection(2).SetData Constants.chDimValues,
Constants.chDataLiteral, values
----------

Thao Moua
OWC Webchart Support
-----Original Message-----
The legned displays all series from "titolo" and datapoint
are returned correctly, except the first one.
You can see my code down this page.
I create my recordset 'on the fly' by the 'getrs' function.
The recordset will appear like this:
data titolo valore
titolo:[pippo] data:[01/01/2003] valore:[6,55]
titolo:[pippo] data:[31/01/2003] valore:[6,2]
titolo:[pippo] data:[28/02/2003] valore:[6,4]
titolo:[pippo] data:[31/03/2003] valore:[6,12]
titolo:[pluto] data:[01/01/2003] valore:[5,55]
titolo:[pluto] data:[31/01/2003] valore:[5,6]
titolo:[pluto] data:[28/02/2003] valore:[5,65]
titolo:[pluto] data:[31/03/2003] valore:[5,72]
titolo:[paperino] data:[01/01/2003] valore:[6]
titolo:[paperino] data:[31/01/2003] valore:[6]
titolo:[paperino] data:[28/02/2003] valore:[5,7]
titolo:[paperino] data:[31/03/2003] valore:[5,75]
thank you very much
G.
-----Original Message-----
Several things you can do to figure this out. See if the
legend displays all the series name from "tilolo" and
very the returned data from the three fields "tilolo,
data, and valore" are valid.

If possible can I see your data and code? Thanks.

Thao Moua
OWC Webchart Support
-----Original Message-----
Thanks, this is better...but still not the best: the
first
record doesn't bound to chart...
-----Original Message-----
Sometime the order of your SetData() matters.

Try this
ChartSpace.SetData c.chDimSeriesNames,0, "titolo"
ChartSpace.SetData c.chDimCategories,0, "data"
ChartSpace.SetData c.chDimValues, 0, "valore"

Thao Moua
OWC WebChart Support
-----Original Message-----
Could someone help me to understand why this script
doesn't work well?
As you can see I've a recordset with 3 series, but
only
two of them appear properly on my chart: it seems the
first 3 records doesn't bound to chart.
Thank you very much! ;-)
Ciao, Gianni

<%@language="vbscript" lcid="1040"%>
<% Option Explicit %>
<%

dim rsch
set rsch = getrs()

Dim ChartSpace, c, objChart
Set ChartSpace = server.CreateObject
("OWC10.ChartSpace")
ChartSpace.clear
Set c = ChartSpace.Constants

set ChartSpace.DataSource = rsch
ChartSpace.Charts(0).HasLegend = True
ChartSpace.Charts(0).HasTitle = True
ChartSpace.Charts(0).Title.Caption = "Andamento.."
ChartSpace.Charts(0).Type =
c.chChartTypeLineMarkers
ChartSpace.DisplayFieldButtons = false


ChartSpace.SetData c.chDimCategories,0, "data"
ChartSpace.SetData c.chDimSeriesNames,0, "titolo"
ChartSpace.SetData c.chDimValues, 0, "valore"

Response.Expires = 0
Response.Buffer = True
Response.Clear
Response.ContentType = "image/gif"
Response.BinaryWrite ChartSpace.GetPicture("gif",
564,300)
Response.Flush

%>

<%
Function getrs()
dim rsStato
const adVarChar = 200
set rsStato = server.CreateObject
("ADODB.Recordset")
rsStato.CursorType = 3
rsStato.CursorLocation = 3
rsStato.Fields.Append "titolo",
adVarChar,
10
rsStato.Fields.Append "data", 7, 8
rsStato.Fields.Append "valore", 6, 8

rsStato_Open
rsStato.AddNew
rsStato("titolo") = "pippo"
rsStato("data") = "01/01/03"
rsStato("valore") = 6.55

rsStato.AddNew
rsStato("titolo") = "pippo"
rsStato("data") = "31/01/03"
rsStato("valore") = 6.2

rsStato.AddNew
rsStato("titolo") = "pippo"
rsStato("data") = "28/02/03"
rsStato("valore") = 6.4

rsStato.AddNew
rsStato("titolo") = "pippo"
rsStato("data") = "31/03/03"
rsStato("valore") = 6.12

rsStato.AddNew
rsStato("titolo") = "pluto"
rsStato("data") = "01/01/03"
rsStato("valore") = 5.55

rsStato.AddNew
rsStato("titolo") = "pluto"
rsStato("data") = "31/01/03"
rsStato("valore") = 5.6


rsStato.AddNew
rsStato("titolo") = "pluto"
rsStato("data") = "28/02/03"
rsStato("valore") = 5.65

rsStato.AddNew
rsStato("titolo") = "pluto"
rsStato("data") = "31/03/03"
rsStato("valore") = 5.72

rsStato.AddNew
rsStato("titolo") = "paperino"
rsStato("data") = "01/01/03"
rsStato("valore") = 6

rsStato.AddNew
rsStato("titolo") = "paperino"
rsStato("data") = "31/01/03"
rsStato("valore") = 6


rsStato.AddNew
rsStato("titolo") = "paperino"
rsStato("data") = "28/02/03"
rsStato("valore") = 5.7

rsStato.AddNew
rsStato("titolo") = "paperino"
rsStato("data") = "31/03/03"
rsStato("valore") = 5.75


rsStato.Update
rsStato.MoveFirst
set getrs = rsStato
end function
%>

.

.

.

.
.
.
 
B

bgundas

Please help.(OWC10)

Hello everyone and Thao :). Using owc10 in .net env. with C# I am
trying to get a bar chart created using the data. My problems are 1. I
am getting source errors. 2. I don't know how to create a bar chart
where the months of a year are on the x axis of the chart and each
month shows like 5 different bars for 5 different values that are
coming from the database. As you can see my code works just fine till I
get to the loops. After that, I have no idea how to get my code to
display multiple series bar-chart.

Here the current error that I am getting:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object. THE LINE IS MARKED AND IN THE FUNCTION
"private void loadChart (int _s, int _data, string _monthYear)"

Herer is the my code, the whole page.


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
page start
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Web.Security;
using System.Xml;
using OWC10;
using System.IO;

namespace RecoveryToolset
{
/// <summary>
/// Summary description for team.
/// </summary>
public class team : System.Web.UI.Page
{
protected OleDbConnection m_myConnection;
protected DataTable dt_dailyTotals;
protected System.Web.UI.WebControls.Button btnChart;
protected System.Web.UI.WebControls.DropDownList ddl_goBack;
protected System.Web.UI.WebControls.DropDownList ddl_dataType;
protected System.Web.UI.WebControls.Image img_chart;
protected System.Web.UI.WebControls.Button Button1;
protected OleDbDataAdapter da;
protected OleDbCommand sqlchartSelectCommand;
protected ChartSpaceClass oChartSpace;


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
this.btnChart.Click += new System.EventHandler(this.btnChart_Click);
this.da = new OleDbDataAdapter();
this.sqlchartSelectCommand = new OleDbCommand();
this.sqlchartSelectCommand.Connection = this.m_myConnection;
this.da.SelectCommand = this.sqlchartSelectCommand;

if(!IsPostBack)
{
loadChart(3, 1, "1/2005"); //test
createChartimage();
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.m_myConnection = new OleDbConnection();
this.m_myConnection.ConnectionString =
ConfigurationSettings.AppSettings["mikeconnection"];
this.Button1.Click += new System.EventHandler(this.Button1_Click);
}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect ("test.aspx");//same as allpayments.aspx, for
testing purposes.
}

private void btnChart_Click(object sender, System.EventArgs e)
{
loadChart(1, 1, "1/2005");
// ddl_goBack.SelectedItem.ToString();
createChartimage();
}

private void loadChart (int _s, int _data, string _monthYear)
{
int s = _s;
int data = _data;
string monthYear = _monthYear;
OWC10.ChartSpaceClass oChartSpace = new OWC10.ChartSpaceClass();
oChartSpace.Charts.Add(0);

if (data ==0)
{
this.sqlchartSelectCommand.CommandText = "select RM_MONTH_YEAR,
RM_TEXT, sum(RM_VALUE) "+
"from DAYBREAK.RECOVERY_CHART_DATA where RM_DESCRIPTION not like
'%AMOUNT' and RM_MONTH_YEAR ='"+monthYear+"' "+
"group by RM_MONTH_YEAR, RM_TEXT";
}
else
{
this.sqlchartSelectCommand.CommandText = "select RM_MONTH_YEAR,
RM_TEXT, sum(RM_VALUE) "+
"from DAYBREAK.RECOVERY_CHART_DATA where RM_DESCRIPTION like
'%AMOUNT' and RM_MONTH_YEAR ='"+monthYear+"' "+
"group by RM_MONTH_YEAR, RM_TEXT";
}

//Create and Fill DataSet
DataSet ds = new DataSet();
da.Fill(ds);

//Write DataSet to XML
System.IO.StringWriter sw = new System.IO.StringWriter();
XmlDocument xDoc = new XmlDocument();
ds.WriteXml(sw);
// clean up
da.Dispose();
ds.Dispose();
xDoc.LoadXml(sw.ToString());
sw.Close();

//Read XML put into an array then make a tab-delimited string of
values
System.Xml.XmlNodeList nodes;
nodes = xDoc.ChildNodes.Item(0).ChildNodes;
int nCount = nodes.Count;
string[] aSeries = new string[nCount];
string[] aValues = new string[nCount];
string[] aDescription = new string[nCount];
string seriesName = String.Empty;
string description = String.Empty;
string values = String.Empty;

int j;
for(j=0;j<_s;j++)
{


int i;
for(i=1;i<nCount;i++)
{
aSeries =
nodes.Item(i-1).ChildNodes.Item(0).InnerText;/////////////////////////////////this
line errors out right here



aDescription = nodes.Item(i-1).ChildNodes.Item(1).InnerText;

aValues = nodes.Item(i-1).ChildNodes.Item(2).InnerText;
//Response.Write(NMa + "," +aNames+ "," +aTotals);
}

seriesName = String.Join("\t", aSeries); //Chart control
accepts tab-delimited string of values
description = String.Join("\t", aDescription); //Chart control
accepts tab-delimited string of values
values = String.Join("\t", aValues);

oChartSpace.Charts[0].SeriesCollection.Add(j);
oChartSpace.Charts[0].SeriesCollection[j].SetData(OWC10.ChartDimensionsEnum.chDimSeriesNames,
Convert.ToInt32(OWC10.ChartSpecialDataSourcesEnum.chDataLiteral),
seriesName);
oChartSpace.Charts[0].SeriesCollection[j].SetData(OWC10.ChartDimensionsEnum.chDimCategories,
Convert.ToInt32(OWC10.ChartSpecialDataSourcesEnum.chDataLiteral),description
);
oChartSpace.Charts[0].SeriesCollection[j].SetData(OWC10.ChartDimensionsEnum.chDimValues,
Convert.ToInt32(OWC10.ChartSpecialDataSourcesEnum.chDataLiteral),values
);

aSeries = null;
aValues = null;
aDescription = null;
}
}

private void createChartimage ()
{
//Format Chart and Create image of chart
oChartSpace.Charts[0].HasLegend = true;
string
strFullPathAndName=Server.MapPath(System.DateTime.Now.Ticks.ToString()
+".gif");
oChartSpace.ExportPicture( strFullPathAndName, "gif", 800, 600);
img_chart.ImageUrl=strFullPathAndName;
img_chart.Visible =true;
RemoveFiles(Server.MapPath("."));
}

private void RemoveFiles(string strPath)
{
System.IO.DirectoryInfo di = new DirectoryInfo(strPath);
FileInfo[] fiArr = di.GetFiles();
foreach (FileInfo fi in fiArr)
{
if(fi.Extension.ToString() ==".gif" )
{
// if file is older than 2 minutes, we'll clean it up
TimeSpan min = new TimeSpan(0,0,1,0,0);
if(fi.CreationTime < DateTime.Now.Subtract(min))
{
fi.Delete();
}
}
}
}
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
page end
 
G

GOTmeINtheSYSTEM

Please help.(OWC10)


Hello everyone and Ms. Thao :). Using owc10 in .net env. with C# I am
trying to get a bar chart created using the data. My problems are 1. I
am getting source errors. 2. I don't know how to create a bar chart
where the months of a year are on the x axis of the chart and each
month shows like 5 different bars for 5 different values that are
coming from the database. As you can see my code works just fine till I
get to the loops. After that, I have no idea how to get my code to
display multiple series bar-chart.


Here the current error that I am getting:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object. THE LINE IS MARKED AND IN THE FUNCTION
"private void loadChart (int _s, int _data, string _monthYear)"


Herer is the my code, the whole page.


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
page start
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Web.Security;
using System.Xml;
using OWC10;
using System.IO;


namespace RecoveryToolset


{
/// <summary>
/// Summary description for team.
/// </summary>
public class team : System.Web.UI.Page

{
protected OleDbConnection m_myConnection;
protected DataTable dt_dailyTotals;
protected System.Web.UI.WebControls.Button btnChart;
protected System.Web.UI.WebControls.DropDownList ddl_goBack;
protected System.Web.UI.WebControls.DropDownList ddl_dataType;
protected System.Web.UI.WebControls.Image img_chart;
protected System.Web.UI.WebControls.Button Button1;
protected OleDbDataAdapter da;
protected OleDbCommand sqlchartSelectCommand;
protected ChartSpaceClass oChartSpace;

private void Page_Load(object sender, System.EventArgs e)


{
// Put user code to initialize the page here

this.btnChart.Click += new System.EventHandler(this.btnChart_Click);
this.da = new OleDbDataAdapter();
this.sqlchartSelectCommand = new OleDbCommand();
this.sqlchartSelectCommand.Connection = this.m_myConnection;
this.da.SelectCommand = this.sqlchartSelectCommand;

if(!IsPostBack)


{
loadChart(3, 1, "1/2005"); //test
createChartimage();


}
}


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)

{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);


}


/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()

{
this.Load += new System.EventHandler(this.Page_Load);
this.m_myConnection = new OleDbConnection();
this.m_myConnection.ConnectionString =
ConfigurationSettings.AppSettings["mikeconnection"];

this.Button1.Click += new System.EventHandler(this.Button1_Click);
}


#endregion

private void Button1_Click(object sender, System.EventArgs e)


{
Response.Redirect ("test.aspx");//same as allpayments.aspx, for
testing purposes.


}


private void btnChart_Click(object sender, System.EventArgs e)

{
loadChart(1, 1, "1/2005");
// ddl_goBack.SelectedItem.ToString();
createChartimage();


}


private void loadChart (int _s, int _data, string _monthYear)

{
int s = _s;
int data = _data;
string monthYear = _monthYear;
OWC10.ChartSpaceClass oChartSpace = new OWC10.ChartSpaceClass();
oChartSpace.Charts.Add(0);

if (data ==0)


{
this.sqlchartSelectCommand.CommandText = "select RM_MONTH_YEAR,
RM_TEXT, sum(RM_VALUE) "+
"from DAYBREAK.RECOVERY_CHART_DATA where RM_DESCRIPTION not like

'%AMOUNT' and RM_MONTH_YEAR ='"+monthYear+"' "+
"group by RM_MONTH_YEAR, RM_TEXT";

}


else

{
this.sqlchartSelectCommand.CommandText = "select RM_MONTH_YEAR,
RM_TEXT, sum(RM_VALUE) "+
"from DAYBREAK.RECOVERY_CHART_DATA where RM_DESCRIPTION like

'%AMOUNT' and RM_MONTH_YEAR ='"+monthYear+"' "+
"group by RM_MONTH_YEAR, RM_TEXT";


}


//Create and Fill DataSet
DataSet ds = new DataSet();
da.Fill(ds);

//Write DataSet to XML
System.IO.StringWriter sw = new System.IO.StringWriter();
XmlDocument xDoc = new XmlDocument();
ds.WriteXml(sw);
// clean up
da.Dispose();
ds.Dispose();
xDoc.LoadXml(sw.ToString());
sw.Close();


//Read XML put into an array then make a tab-delimited string of
values
System.Xml.XmlNodeList nodes;
nodes = xDoc.ChildNodes.Item(0).ChildNodes;
int nCount = nodes.Count;


string[] aSeries = new string[nCount];
string[] aValues = new string[nCount];
string[] aDescription = new string[nCount];
string seriesName = String.Empty;
string description = String.Empty;
string values = String.Empty;

int j;


for(j=0;j<_s;j++)
{
int i;


for(i=1;i<nCount;i++)
{
aSeries =
nodes.Item(i-1).ChildNodes.Item(0).InnerText;/////////////////////////////////this
line errors out right here


aDescription = nodes.Item(i-1).ChildNodes.Item(1).InnerText;

aValues = nodes.Item(i-1).ChildNodes.Item(2).InnerText;
//Response.Write(NMa + "," +aNames+ "," +aTotals);

}


seriesName = String.Join("\t", aSeries); //Chart control
accepts tab-delimited string of values
description = String.Join("\t", aDescription); //Chart control
accepts tab-delimited string of values
values = String.Join("\t", aValues);

oChartSpace.Charts[0].SeriesCollection.Add(j);


oChartSpace.Charts[0].SeriesCollection[j].SetData(OWC10.ChartDimensionsEnum.chDimSeriesNames,
Convert.ToInt32(OWC10.ChartSpecialDataSourcesEnum.chDataLiteral),
seriesName);

oChartSpace.Charts[0].SeriesCollection[j].SetData(OWC10.ChartDimensionsEnum.chDimCategories,
Convert.ToInt32(OWC10.ChartSpecialDataSourcesEnum.chDataLiteral),description
);

oChartSpace.Charts[0].SeriesCollection[j].SetData(OWC10.ChartDimensionsEnum.chDimValues,
Convert.ToInt32(OWC10.ChartSpecialDataSourcesEnum.chDataLiteral),values
);

aSeries = null;
aValues = null;
aDescription = null;



}
}


private void createChartimage ()

{
//Format Chart and Create image of chart

oChartSpace.Charts[0].HasLegend = true;
string
strFullPathAndName=Server.MapPath(System.DateTime.Now.Ticks.ToString()
+".gif");
oChartSpace.ExportPicture( strFullPathAndName, "gif", 800, 600);
img_chart.ImageUrl=strFullPathAndName;
img_chart.Visible =true;
RemoveFiles(Server.MapPath("."));


}


private void RemoveFiles(string strPath)

{
System.IO.DirectoryInfo di = new DirectoryInfo(strPath);

FileInfo[] fiArr = di.GetFiles();
foreach (FileInfo fi in fiArr)

{
if(fi.Extension.ToString() ==".gif" )

{
// if file is older than 2 minutes, we'll clean it up
TimeSpan min = new TimeSpan(0,0,1,0,0);
if(fi.CreationTime < DateTime.Now.Subtract(min))

{
fi.Delete();


}
}
}
}
}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
page end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top