change the x axis value of a t-chart point graph

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
cs_ech
Newbie
Newbie
Posts: 14
Joined: Mon Oct 02, 2006 12:00 am

change the x axis value of a t-chart point graph

Post by cs_ech » Tue Aug 04, 2009 4:38 pm

how can i change the value of the x-axis of a t-chart point graph from int to timestamp with format hh:mm:ss.xxxx where xxxx is milliseconds.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: change the x axis value of a t-chart point graph

Post by Yeray » Wed Aug 05, 2009 8:25 am

Hi cs_ech,

I think you are looking for that:

Code: Select all

series1.XValues.DateTime = true;
tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:ss.ffff";
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

cs_ech
Newbie
Newbie
Posts: 14
Joined: Mon Oct 02, 2006 12:00 am

Re: change the x axis value of a t-chart point graph

Post by cs_ech » Tue Nov 03, 2009 11:11 pm

so I added the following lines in my code:

points1.XValues.DateTime = true;
tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:ss.ffff";

while (rdr.Read() )
{
DateTime dt = (System.DateTime)rdr.GetValue(0);
Double latency = (Double)rdr.GetValue(1);
Console.WriteLine(counter);
f1.points1.Add(dt, latency);
counter++;
}

However, I do not see an even x-axis spread. I am plotting data ranging from time 8am to 4pm, but, I see 5 divisions of 12:00:00.00 on x-axis. I expect to see 8:00:00.0000 10:00:00.0000 12:00:00.0000 2:00:00.0000 and 4:00:00.0000.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: change the x axis value of a t-chart point graph

Post by Sandra » Wed Nov 04, 2009 11:16 am

Hello cs_ech,

For reproduce your problem we need yor fiel. Please you could send us a simple project because we could investigated your problem here?



Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

cs_ech
Newbie
Newbie
Posts: 14
Joined: Mon Oct 02, 2006 12:00 am

Re: change the x axis value of a t-chart point graph

Post by cs_ech » Wed Nov 04, 2009 10:56 pm

private void BuildGraphs_Click(object sender, EventArgs e)
{
IDbConnection conn = Get_Connection();

IEnumerator AgoraChecklistEnumerator;
AgoraChecklistEnumerator = AgoraInstancesCheckList.CheckedIndices.GetEnumerator();
int AgoraInstance;
while (AgoraChecklistEnumerator.MoveNext() != false)
{
AgoraInstance = (int)AgoraChecklistEnumerator.Current;
AgoraInstancesCheckList.SetItemChecked(AgoraInstance, false);
DrawPointGraph drawIt = new DrawPointGraph();
GraphForm test_form1 = new GraphForm();
test_form1.name_graph(AgoraInstance);
drawIt.draw_graph(AgoraInstance, test_form1, conn, TableName);
test_form1.Show();
}

public class DrawPointGraph
{
public void draw_graph(int agoraInstance, GraphForm f1, IDbConnection conn, string TableName)
{
string sql;
if (agoraInstance == 0)
{
sql = "select a, aLatency from a.b7 order by a";
}else
{
sql = "select a, aLatency from a.b7 where a=" + ae +" order by a";
}

conn.Open();
IDbCommand command = conn.CreateCommand();
command.CommandTimeout = 2000;
command.CommandText = sql;
IDataReader rdr = command.ExecuteReader();
int counter = 0;

while (rdr.Read() && counter<100 )
{
DateTime dt = (System.DateTime)rdr.GetValue(0);
Double latency = (Double)rdr.GetValue(1);
Console.WriteLine(counter);
f1.points1.Add(dt, latency);
counter++;
}
conn.Close();
}

I am simply retriving data from the db and plotting the graph. Datetime as x axis value and double as y axis value.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: change the x axis value of a t-chart point graph

Post by Narcís » Thu Nov 05, 2009 10:23 am

Hello,

You could try setting desired bottom axis DateTime increment as shown here.

Also please notice that TeeChart tries to plot as many labels as possible in the axes according to their Increment property and not allowing labels to overlap. So it may help you getting more labels than those displayed setting labels Angle to 90, for example:

Code: Select all

tChart1.Axes.Bottom.Labels.Angle = 90;
Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

cs_ech
Newbie
Newbie
Posts: 14
Joined: Mon Oct 02, 2006 12:00 am

Re: change the x axis value of a t-chart point graph

Post by cs_ech » Thu Nov 05, 2009 11:56 pm

The data that i retieve is in the datetime format:
8/24/2009 9:35:11 AM
8/24/2009 9:35:30 AM
8/24/2009 9:35:33 AM
8/24/2009 9:35:36 AM
8/24/2009 2:19:31 PM
8/24/2009 2:19:31 PM
8/24/2009 2:19:32 PM
8/24/2009 3:05:00 PM
8/24/2009 3:05:00 PM
8/24/2009 3:05:00 PM

I am not sure how the follwoing add method works:
DateTime dt = (System.DateTime)rdr.GetValue(0); //where rdr is the Idatareader. The sample pf the data that is being retrieved is given above
Double latency = (Double)rdr.GetValue(1);
f1.points1.Add(dt,latency);

I tried f1.points1.Add(latency); instead and I get the same x-axis spread as when i use f1.points1.Add(dt,latency).
This means that the the add method overload that takes two arguments of type datetime and double is not working correctly. Do i need to reformat the datetime data that i get (ie: 8/24/2009 3:05:00 PM) ?

I am plotting data ranging from time 9:35am to 3:05pm, but, I see divisions of 12:00:00.00 on x-axis. I expect to see 9:35:00.0000 10:35:00.0000 11:35:00.0000 12:35:00.0000 1:35:00.0000... and so on

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: change the x axis value of a t-chart point graph

Post by Sandra » Fri Nov 06, 2009 12:08 pm

Hello cs_ech,

I commented two things about your issue:
I tried f1.points1.Add(latency); instead and I get the same x-axis spread as when i use f1.points1.Add(dt,latency).
This means that the the add method overload that takes two arguments of type datetime and double is not working correctly.
First, I don't could reproduce your problem, I made a simple example that add a dateTime and a Double and works correctly. Please, check that this application works fine.

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Bar bar1;
        private void InitializeChart()
        {
            Random rnd = new Random();
            DateTime today = DateTime.Today;
            TimeSpan twohours = TimeSpan.FromHours(2);
            bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.XValues.DateTime = true;

            for (int i = 1; i <= 5; i++)
            {
                bar1.Add(today, rnd.Next(100));
                today += twohours;
            }
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:ss.ffff";
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoHours);
        }
    }
}
Second, Could you please arrange a simple example project we can run "as-is" to reproduce the problem here?

You can create a dataset at runtime as Christoper Ireland's example here.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

cs_ech
Newbie
Newbie
Posts: 14
Joined: Mon Oct 02, 2006 12:00 am

Re: change the x axis value of a t-chart point graph

Post by cs_ech » Fri Nov 06, 2009 7:42 pm

Please change the graph type to point instead of bar and then increae the data size from 5 to 5000 and to reproduce the error that I get:

private Steema.TeeChart.Styles.Points point1;
private void InitializeChart()
{
System.Random rnd = new System.Random();
System.DateTime today = System.DateTime.Today;
System.TimeSpan twohours = System.TimeSpan.FromMinutes(20.5);
point1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
point1.XValues.DateTime = true;

for (int i = 1; i <= 500; i++)
{
point1.Add(today, rnd.Next(100));
today += twohours;
}
tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:ss.ffff";
tChart1.Axes.Bottom.Labels.Angle = 90;
tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoHours);
this.Show();
}

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: change the x axis value of a t-chart point graph

Post by Sandra » Mon Nov 09, 2009 9:48 am

Hello cs_ech,

I reproduce your problem, but this is not an error is a behavior of TeeChart. It when there are many labels not paint all, choose automatically intervals, because labels aren't overlapping. If you want always show all labels, there is only one solution use custom labels, but if you add many points, is likely that labels overlap, because depends of chart size and this is limited of screen resolution.

I made a simple example, that add custom labels in Bottom Axes of Chart.

Code: Select all

       private Steema.TeeChart.Styles.Points points1;
        private void InitializeChart()
        {
            Random rnd = new Random();
            DateTime today = DateTime.Today;
            TimeSpan twohours = TimeSpan.FromMinutes(20.5);
            tChart1.Dock = DockStyle.Fill;
            points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            tChart1.Aspect.View3D = false;
            points1.XValues.DateTime = true;
            tChart1.Panel.MarginBottom = 20;
            for (int i = 5; i <= 50; i++)
            {
                points1.Add(today, rnd.Next(100));
                today += twohours;
            }
            tChart1.Axes.Bottom.Labels.Items.Clear();
            for (int i = 0; i < points1.Count; i++)
            {
                tChart1.Axes.Bottom.Labels.Items.Add(points1.XValues[i], points1.Labels[i]);
            }
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:ss.ffff";
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoHours);
            }
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply