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
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