thanks,
Rich
Code: Select all
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.Web.Handlers;
using System.IO;
using System.Text;
using Steema.TeeChart.Web;
using Steema.TeeChart.Styles;
public partial class _Default : System.Web.UI.Page
{
private int clickedX;
private int clickedY;
private string msgText;
private DataBase db = new DataBase();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillChart();
getDetailedData();
}
ChartSession();
CheckZoom(WebChart1);
}
protected void FillChart()
{
Steema.TeeChart.Chart chart1 = WebChart1.Chart;
Steema.TeeChart.Styles.Volume series1 = (Steema.TeeChart.Styles.Volume)chart1.Series[0];
chart1.Tools.Add(new Steema.TeeChart.Tools.ZoomTool());
((Steema.TeeChart.Tools.ZoomTool)chart1.Tools[0]).ZoomPenColor = Color.OliveDrab;
//chart1.Tools.Add(new Steema.TeeChart.Tools.ScrollTool());
series1.XValues.DateTime = true;
chart1.Axes.Bottom.Labels.DateTimeFormat = "MM/yyyy";
chart1.Axes.Bottom.Labels.MultiLine = true;
chart1.Panel.MarginBottom = 10;
// Legend
Steema.TeeChart.Legend legend = chart1.Legend;
legend.ImageMode = Steema.TeeChart.Drawing.ImageMode.Stretch;
DataSet ds = new DataSet();
ds = getSummaryData();
series1.Title = "Date/Time";
int numOfRows = ds.Tables["summary"].Rows.Count;
/*
double[] arrTime = new double[numOfRows];
DateTime[] arrDate = new DateTime[numOfRows];
for (int i = 0; i < numOfRows; i++)
{
DataRow row = db.dtSummary.Tables["summary"].Rows[i];
arrTime[i] = Convert.ToDouble(row["TOTAL_TIME"]);
arrDate[i] = Convert.ToDateTime(row["APPROVE_DT"]);
}
*/
series1.Clear();
series1.DataSource = ds.Tables["summary"];
series1.XValues.DataMember = "APPROVE_DT";
series1.YValues.DataMember = "TOTAL_TIME";
series1.CheckDataSource();
//series1.Add(arrDate, arrTime);
}
private DataSet getSummaryData()
{
DataSet ds = new DataSet();
if (db.open())
{
db.getSummaryDataSet();
ds = db.dtSummary;
}
return ds;
}
private DataSet getDetailedData()
{
DataSet ds = new DataSet();
if (db.open())
{
db.getDetailedDataSet();
ds = db.dtDetailed;
}
return ds;
}
protected void ChartSession()
{
Steema.TeeChart.Chart ch1 = WebChart1.Chart;
MemoryStream tmpChart = new MemoryStream();
if (Session["WebChart1"] == null)
{
//export Chart to a MemoryStream template
ch1.Export.Template.Save(tmpChart);
//save template to a Session variable
Session.Add("WebChart1", tmpChart);
}
else
{
//retrieve the session stored Chart
tmpChart = (MemoryStream)Session["WebChart1"];
//set the Stream position to 0 as the last read/write
//will have moved the position to the end of the stream
tmpChart.Position = 0;
//import saved Chart
WebChart1.Chart.Import.Template.Load(tmpChart);
}
}
private void CheckZoom(WebChart wChart)
{
ArrayList zoomedState = (ArrayList)Session[wChart.ID + "Zoomed"];
if (wChart.Chart.Tools.Count > 0)
{
zoomedState = ((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(Request,
zoomedState);
if (zoomedState == null)
Session.Remove(wChart.ID + "Zoomed");
else
{
Session.Add(wChart.ID + "Zoomed", zoomedState);
}
}
}
public void WebChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
//output text message to the rendered Chart.
if (clickedX != -1)
{
//g.Font.Bold=true;
g.Font.Color = Color.OrangeRed;
g.TextOut(clickedX, clickedY, msgText);
}
}
public void WebChart1_ClickBackground(object sender, System.Web.UI.ImageClickEventArgs e)
{
//event triggered when any point on the Chart is clicked. If the ClickSeries event is active
//it will take precedence when a Series is clicked.
clickedX = e.X;
clickedY = e.Y;
msgText = "Clicked background\n\rX:" + WebChart1.Chart.Axes.Bottom.CalcPosPoint(clickedX).ToString("#0.00")
+ ", Y:" + WebChart1.Chart.Axes.Left.CalcPosPoint(clickedY).ToString("#0.00");
}
public void WebChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, System.EventArgs e)
{
Steema.TeeChart.Chart tChart = ((WebChart)sender).Chart;
clickedX = s.CalcXPos(valueIndex);
clickedY = s.CalcYPos(valueIndex);
msgText = "Clicked Series: " + tChart.Series.IndexOf(s).ToString() + "\n\rValue: " + s.YValues[valueIndex].ToString("#0.00");
}
}
// Database obj
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.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.OracleClient;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
/// <summary>
/// Summary description for DataBase
/// </summary>
public class DataBase
{
//Database access variables
private string ConnectionString;
protected System.Data.OracleClient.OracleConnection dbConnection;
protected System.Data.OracleClient.OracleCommand dbCommand;
protected System.Data.OracleClient.OracleDataReader dbReader;
protected System.Data.OracleClient.OracleDataAdapter dbAdapter;
private string strDetailedSelect = "SELECT PROGRAM_ID, ORDERID, ORDERSEQ, CONTRACT_NUM, DELIVERY_ORDER_NUM, APPROVED_CD, APPROVE_BUYER, LOAD_DT, SUBMIT_DT, " +
"VENDOR_REVIEW_DT, DSCP_TIME, VEND_TIME, CAT_TYPE FROM PV_USAGE_HDR WHERE APPROVED_CD = 'A' AND SUBSTR(APPROVE_BUYER,1,4) <> 'AUTO'";
private string strSummarySelect = "SELECT PROGRAM_ID, ORDERID, CONTRACT_NUM, DELIVERY_ORDER_NUM, APPROVE_BUYER, APPROVE_DT, SUBMIT_DT, " +
"TOTAL_TIME, CAT_TYPE FROM PV_USAGE_SUMMARY WHERE SUBSTR(APPROVE_BUYER,1,4) <> 'AUTO'";
public DataSet dtDetailed = new DataSet();
public DataSet dtSummary = new DataSet();
public DataBase()
{
}
public bool open()
{
ConnectionString = "User ID=myid;Password=mypass;Data Source=mydb";
dbConnection = new OracleConnection(ConnectionString);
dbConnection.Open();
if (dbConnection.State != ConnectionState.Open)
{
return false;
}
return true;
}
public void getDetailedDataSet()
{
if (dtDetailed.Tables.Count != 0)
return;
if (dbConnection.State != ConnectionState.Open)
dbConnection.Open();
dbCommand = new OracleCommand();
dbCommand.CommandType = CommandType.Text;
dbCommand.Connection = dbConnection;
//Read detailed dataset from database
dbCommand.CommandText = strDetailedSelect;
dbAdapter = new OracleDataAdapter(strDetailedSelect, dbConnection);
dbAdapter.Fill(dtDetailed, "detailed");
dbAdapter.Dispose();
dbConnection.Close();
}
public void getSummaryDataSet()
{
if (dtSummary.Tables.Count != 0)
return;
if (dbConnection.State != ConnectionState.Open)
dbConnection.Open();
dbCommand = new OracleCommand();
dbCommand.CommandType = CommandType.Text;
dbCommand.Connection = dbConnection;
//Read detailed dataset from database
dbCommand.CommandText = strDetailedSelect;
dbAdapter = new OracleDataAdapter(strSummarySelect, dbConnection);
dbAdapter.Fill(dtSummary, "summary");
dbAdapter.Dispose();
dbConnection.Close();
}
public DateTime OracleDateToDateTime(string oDate)
{
// taking the format of dd/mm/yyyy ...
string[] arr = oDate.Split(new char[] { '/' });
int day = int.Parse(arr[0]);
int month = int.Parse(arr[1]);
int year = int.Parse(arr[2]);
DateTime dt = new DateTime(year, month, day);
return dt;
}
}