position second series in a chart (OWC10)

K

kkzhao

I have a question on OWC10 charting. Can you help?
I am using the OWC10 in ASP.Net, it works fine if I display only one
series. However, if I add the second series, the second series is being
placed to the right side of the first series. It should be kind of in
the middle based on it value.

It would be better if I can attach the screen shot of my chart here.

In my code the arrProbability[0],
arrProbabilityValue[0],arrProbability[1],arrProbabilityValue[1] contain
the tab delimited value I get from database.

Thank you.

Eric
(e-mail address removed)
(415)768-4070

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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.Data.OleDb;
using System.Data.SqlClient;
using OWC10;

namespace TestApp
{
/// <summary>
/// Summary description for RiskCurve.
/// </summary>
public class RiskCurve : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder
phRiskCurve;
protected OWC10.ChartSpace objCSpace;
protected OWC10.ChChart objChart;
protected OWC10.ChartChartTypeEnum c;
protected System.Object obj;
protected int i;

private void Page_Load(object sender,
System.EventArgs e)
{
//
arrProbability[0] = "-2.4 -2.3 -2.2
-2.1 -2 -1.9 -1.8 -1.7 -1.6
-1.5 -1.4 -1.3 -1.2 -1.1 -1
-0.9 -0.8 -0.7 -0.6 -0.5 -0.4
-0.3 -0.2 -0.1 0 0.1 0.2
0.3 0.4 0.5 0.6 0.7 0.8
0.9 "

arrProbabilityValue[0] = "0.0005 0.0005
0.0005 0.0005 0.0005 0.0005 0.0005 0.0005
0.0005 0.0005 0.0005 0.001 0.002 0.003
0.005 0.0085 0.015 0.0255 0.0425 0.0705
0.114 0.1785 0.2705 0.392 0.537 0.6915
0.8305 0.9295 0.9805 0.997 0.9995 0.9995
0.9995 0.9995 "

arrProbability[1] = "0.044538193348157
0.044538193348157 "

arrProbabilityValue[1] = "1 0 "

objCSpace = new OWC10.ChartSpace();
obj = objCSpace.Constants;
objChart = objCSpace.Charts.Add(0);
objChart.Type =
OWC10.ChartChartTypeEnum.chChartTypeSmoothLine;
objChart.HasTitle = false;
objChart.Axes[0].HasTitle=true;
objChart.Axes[0].Title.Caption= "Profit
(Loss): GM%";
objChart.Axes[1].HasTitle=true;
objChart.Axes[1].Title.Caption= "Probability
that GM% will be less than amount shown";
objChart.Axes[1].HasAutoMajorUnit=true;
objChart.Axes[1].MajorUnit = 0.1;
objChart.Axes[1].NumberFormat="0%";

objChart.SeriesCollection.Add(1);
objChart.SeriesCollection.Add(1);
objChart.SeriesCollection.Add(1);

objChart.SeriesCollection[0].SetData(OWC10.Char-
tDimensionsEnum.chDimSeriesNames,(int)OWC10.Cha-
rtSpecialDataSourcesEnum.chDataLiteral,"Risk1");
objChart.SeriesCollection[0].SetData(OWC10.Char-
tDimensionsEnum.chDimCategories,(int)OWC10.Char-
tSpecialDataSourcesEnum.chDataLiteral,arrProbab-
ility[0]);
objChart.SeriesCollection[0].SetData(OWC10.Char-
tDimensionsEnum.chDimValues,(int)OWC10.ChartSpe-
cialDataSourcesEnum.chDataLiteral,arrProbabilit-
yValue[0]);

objChart.SeriesCollection[1].SetData(OWC10.Char-
tDimensionsEnum.chDimSeriesNames,(int)OWC10.Cha-
rtSpecialDataSourcesEnum.chDataLiteral,"Risk2");
objChart.SeriesCollection[1].SetData(OWC10.Char-
tDimensionsEnum.chDimCategories,(int)OWC10.Char-
tSpecialDataSourcesEnum.chDataLiteral,arrProbab-
ility[1]);
objChart.SeriesCollection[1].SetData(OWC10.Char-
tDimensionsEnum.chDimValues,(int)OWC10.ChartSpe-
cialDataSourcesEnum.chDataLiteral,arrProbabilit-
yValue[1]);

objChart.SeriesCollection[2].SetData(OWC10.Char-
tDimensionsEnum.chDimSeriesNames,(int)OWC10.Cha-
rtSpecialDataSourcesEnum.chDataLiteral,"Risk3");
objChart.SeriesCollection[2].SetData(OWC10.Char-
tDimensionsEnum.chDimCategories,(int)OWC10.Char-
tSpecialDataSourcesEnum.chDataLiteral,arrProbab-
ility[2]);
objChart.SeriesCollection[2].SetData(OWC10.Char-
tDimensionsEnum.chDimValues,(int)OWC10.ChartSpe-
cialDataSourcesEnum.chDataLiteral,arrProbabilit-
yValue[2]);

objChart.SeriesCollection[0].Interior.Color =
"Rosybrown";
objChart.SeriesCollection[1].Interior.Color =
"red";
objChart.SeriesCollection[2].Interior.Color =
"blue";
objChart.PlotArea.Interior.Color = "white";
objCSpace.Border.Color="Blue";

string strAbsolutePath = (Server.MapPath(".")) +
"\\Temp\\TestChart.gif";
objCSpace.ExportPicture(strAbsolutePath,"GIF",-
700, 450);
string strRelativePath = "./Temp/TestChart.gif";
string strImageTag = "<img src='" +
strRelativePath + "'/>";

phRiskCurve.Controls.Add(new
LiteralControl(strImageTag));
}

#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);

}
#endregion
}
}
 
B

bgundas

Please help.(OWC10)


Hello everyone and Mr. Bruney. :). 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