x-axis values
Posted: Thu Oct 05, 2006 10:42 am
Hi,
I posted this before but I could not send the attachement on the newsgroup so I send it on Narcis email. I have not received any reply so I am posting it all over again. I am sending attachemnt on Narcis mail again. Please let me knowif I need to send it anywhere else. Newsgroup is not working for us.
We are using TeeChart.NET version 2 (Build 2.0.2306.26231).
Our main goal is to get EXACT start date-time and end date-time from X-axis when user selects area to "zoom". For that purpose, we intend to have labels on X-axis with one second margin. So that after zoom, we could retrieve EXACT date-time of zoom area from "FirstVisibleIndex" and "LastVisibleIndex" properties.
We tried the solution you provided as below:
trendChart.Axes.Bottom.Increment = (double)Steema.TeeChart.DateTimeSteps.OneSecond;
trendChart.Axes.Bottom.Labels.Separation = 0;
//////////Zero separation to have all labels. As our requirement, we only need to show start and end label on X-axis, so we do not worry about cluttered variables [we have taken that care in "GetAxisLabel" event]
If you see text file of labels, it only prints labels what are there in database, and not labels with difference of one second. It seems TeeChart calculates "how many" labels to print before rendering the control.
Would you please guide us in how to get EXACT X-axis date-time values when user zooms the chart area.
here is code
Code:
using System;
using System.IO;
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 Steema.TeeChart;
using Steema.TeeChart.Web;
using Steema.TeeChart.Tools;
namespace Lilly.B130BatchTools
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected Steema.TeeChart.Web.WebChart webChart;
private int m_maxCount = 0;
private const string dbPath = @"c:\inetpub\wwwroot\db1.mdb";
private const string filePath = @"c:\inetpub\wwwroot\labels.txt";
private void Page_Load(object sender, System.EventArgs e)
{
Steema.TeeChart.Styles.Line lineValue = null;
Steema.TeeChart.Chart trendChart = null;
Axis multiAxes = null;
if (File.Exists(filePath))
{
File.Delete(filePath);
}
webChart.Clear();
trendChart = webChart.Chart;
trendChart.Legend.Alignment =
Steema.TeeChart.LegendAlignments.Top;
trendChart.Axes.Bottom.Title.Text = "Time";
trendChart.Axes.Bottom.Title.Font.Color = Color.DarkGray;
trendChart.Axes.Bottom.Labels.Angle = 90;
trendChart.Axes.Bottom.Increment =
(double)Steema.TeeChart.DateTimeSteps.OneSecond;
trendChart.Axes.Bottom.Labels.Separation = 0;
trendChart.Axes.Left.Title.Text = "Point Values";
trendChart.Axes.Left.Title.Font.Color = Color.DarkGray;
trendChart.Aspect.View3D = false;
trendChart.Walls.Visible = false;
webChart.Chart.Series.RemoveAllSeries();
string query = "SELECT PointValue, TimeValue FROM Point{0}";
OleDbConnection cn = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath);
cn.Open();
DataSet dataSet = null;
OleDbDataAdapter da = null;
DataTable table = null;
m_maxCount = 0;
for (int i = 1; i < 3; i++)
{
query = String.Format(query, i.ToString());
da = new OleDbDataAdapter(query, cn);
dataSet = new DataSet();
da.Fill(dataSet);
table = dataSet.Tables[0];
if (table.Rows.Count > m_maxCount)
{
m_maxCount = table.Rows.Count;
}
lineValue = new Steema.TeeChart.Styles.Line();
lineValue.Title = "Point" + i.ToString();
lineValue.YValues.DataMember =
table.Columns["PointValue"].ToString();
lineValue.XValues.DateTime = true;
lineValue.LabelMember = table.Columns["TimeValue"].ToString();
lineValue.XValues.DataMember =
table.Columns["TimeValue"].ToString();
lineValue.DataSource = table;
trendChart.Series.Add(lineValue);
if (i == 1)
{
trendChart.Axes.Left.AxisPen.Color =
lineValue.Color;
}
else
{
multiAxes = new Axis(
false, false, webChart.Chart);
multiAxes.AxisPen.Color = lineValue.Color;
multiAxes.PositionUnits = PositionUnits.Percent;
multiAxes.RelativePosition = 6 * (i-1);
webChart.Chart.Axes.Custom.Add(multiAxes);
lineValue.CustomVertAxis = multiAxes;
}
}
cn.Close();
Steema.TeeChart.Themes.ColorPalettes.ApplyPalette(
trendChart.Chart,7);
webChart.Chart.Legend.LegendStyle =
Steema.TeeChart.LegendStyles.Series;
webChart.Chart.Header.Visible = false;
webChart.Visible = true;
}
#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.webChart.GetAxisLabel += new Steema.TeeChart.GetAxisLabelEventHandler(this.webChart_GetAxisLabel);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void webChart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
{
if(((Steema.TeeChart.Axis)sender).Equals(webChart.Chart.Axes.Bottom))
{
StreamWriter sw = File.AppendText(filePath);
sw.WriteLine(e.LabelText);
sw.Close();
if (e.ValueIndex > 0 && e.ValueIndex < (m_maxCount - 1))
{
e.LabelText = "";
}
}
}
}
}
I posted this before but I could not send the attachement on the newsgroup so I send it on Narcis email. I have not received any reply so I am posting it all over again. I am sending attachemnt on Narcis mail again. Please let me knowif I need to send it anywhere else. Newsgroup is not working for us.
We are using TeeChart.NET version 2 (Build 2.0.2306.26231).
Our main goal is to get EXACT start date-time and end date-time from X-axis when user selects area to "zoom". For that purpose, we intend to have labels on X-axis with one second margin. So that after zoom, we could retrieve EXACT date-time of zoom area from "FirstVisibleIndex" and "LastVisibleIndex" properties.
We tried the solution you provided as below:
trendChart.Axes.Bottom.Increment = (double)Steema.TeeChart.DateTimeSteps.OneSecond;
trendChart.Axes.Bottom.Labels.Separation = 0;
//////////Zero separation to have all labels. As our requirement, we only need to show start and end label on X-axis, so we do not worry about cluttered variables [we have taken that care in "GetAxisLabel" event]
If you see text file of labels, it only prints labels what are there in database, and not labels with difference of one second. It seems TeeChart calculates "how many" labels to print before rendering the control.
Would you please guide us in how to get EXACT X-axis date-time values when user zooms the chart area.
here is code
Code:
using System;
using System.IO;
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 Steema.TeeChart;
using Steema.TeeChart.Web;
using Steema.TeeChart.Tools;
namespace Lilly.B130BatchTools
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected Steema.TeeChart.Web.WebChart webChart;
private int m_maxCount = 0;
private const string dbPath = @"c:\inetpub\wwwroot\db1.mdb";
private const string filePath = @"c:\inetpub\wwwroot\labels.txt";
private void Page_Load(object sender, System.EventArgs e)
{
Steema.TeeChart.Styles.Line lineValue = null;
Steema.TeeChart.Chart trendChart = null;
Axis multiAxes = null;
if (File.Exists(filePath))
{
File.Delete(filePath);
}
webChart.Clear();
trendChart = webChart.Chart;
trendChart.Legend.Alignment =
Steema.TeeChart.LegendAlignments.Top;
trendChart.Axes.Bottom.Title.Text = "Time";
trendChart.Axes.Bottom.Title.Font.Color = Color.DarkGray;
trendChart.Axes.Bottom.Labels.Angle = 90;
trendChart.Axes.Bottom.Increment =
(double)Steema.TeeChart.DateTimeSteps.OneSecond;
trendChart.Axes.Bottom.Labels.Separation = 0;
trendChart.Axes.Left.Title.Text = "Point Values";
trendChart.Axes.Left.Title.Font.Color = Color.DarkGray;
trendChart.Aspect.View3D = false;
trendChart.Walls.Visible = false;
webChart.Chart.Series.RemoveAllSeries();
string query = "SELECT PointValue, TimeValue FROM Point{0}";
OleDbConnection cn = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath);
cn.Open();
DataSet dataSet = null;
OleDbDataAdapter da = null;
DataTable table = null;
m_maxCount = 0;
for (int i = 1; i < 3; i++)
{
query = String.Format(query, i.ToString());
da = new OleDbDataAdapter(query, cn);
dataSet = new DataSet();
da.Fill(dataSet);
table = dataSet.Tables[0];
if (table.Rows.Count > m_maxCount)
{
m_maxCount = table.Rows.Count;
}
lineValue = new Steema.TeeChart.Styles.Line();
lineValue.Title = "Point" + i.ToString();
lineValue.YValues.DataMember =
table.Columns["PointValue"].ToString();
lineValue.XValues.DateTime = true;
lineValue.LabelMember = table.Columns["TimeValue"].ToString();
lineValue.XValues.DataMember =
table.Columns["TimeValue"].ToString();
lineValue.DataSource = table;
trendChart.Series.Add(lineValue);
if (i == 1)
{
trendChart.Axes.Left.AxisPen.Color =
lineValue.Color;
}
else
{
multiAxes = new Axis(
false, false, webChart.Chart);
multiAxes.AxisPen.Color = lineValue.Color;
multiAxes.PositionUnits = PositionUnits.Percent;
multiAxes.RelativePosition = 6 * (i-1);
webChart.Chart.Axes.Custom.Add(multiAxes);
lineValue.CustomVertAxis = multiAxes;
}
}
cn.Close();
Steema.TeeChart.Themes.ColorPalettes.ApplyPalette(
trendChart.Chart,7);
webChart.Chart.Legend.LegendStyle =
Steema.TeeChart.LegendStyles.Series;
webChart.Chart.Header.Visible = false;
webChart.Visible = true;
}
#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.webChart.GetAxisLabel += new Steema.TeeChart.GetAxisLabelEventHandler(this.webChart_GetAxisLabel);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void webChart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
{
if(((Steema.TeeChart.Axis)sender).Equals(webChart.Chart.Axes.Bottom))
{
StreamWriter sw = File.AppendText(filePath);
sw.WriteLine(e.LabelText);
sw.Close();
if (e.ValueIndex > 0 && e.ValueIndex < (m_maxCount - 1))
{
e.LabelText = "";
}
}
}
}
}