X Axis - Date formatting

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
jamesl
Newbie
Newbie
Posts: 10
Joined: Wed May 23, 2007 12:00 am
Contact:

X Axis - Date formatting

Post by jamesl » Wed Oct 17, 2007 2:44 pm

I have a chart on a webform and at runtime I want to change the x axis date format to either Day, Week, Month, Year etc.

With the code below I see a line chart only between the specific dates from the data (I'd like to see from eg 1/1/2007 to 31/12/2007 or months 1 to 12).

Steema.TeeChart.Chart Chart2 = WebChartControl1.Chart;
Steema.TeeChart.Styles.Line line2 = new Steema.TeeChart.Styles.Line(Chart2);
line2.Chart.Axes.Bottom.Labels.Angle = 90;
ine2.YValues.DataMember = tbl.Columns["Net_Total"].ToString();
line2.LabelMember = tbl.Columns["Invoice_Date"].ToString();
line2.DataSource = tbl;


I presume the chart I see is an automatic interpretation. Looking through the forum and the tutorial I inserted the following code which I would have thought would manually format the axis.

line2.XValues.DateTime = true;
line2.Chart.Axes.Bottom.Automatic = false;
line2.Chart.Axes.Bottom.SetMinMax(DateTime.Parse"01/01/2007"), DateTime.Parse("31/12/2007"));
line2.Chart.Axes.Bottom.Labels.DateTimeFormat = "mm/dd";


Inserting this code makes my chart line and x labels disappear - what am I doing wrong ?

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

Post by Narcís » Wed Oct 17, 2007 2:59 pm

Hi jamesl,

Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance!
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

jamesl
Newbie
Newbie
Posts: 10
Joined: Wed May 23, 2007 12:00 am
Contact:

Post by jamesl » Thu Oct 18, 2007 11:34 am

Hi Narcis

I seem to be getting there - what I need is to set the increment.
When I use the following code as instructed in the tutorial(axis control/increment)


Steema.TeeChart.Axis bottomAxis = WebChartControl1.Chart.Axes.Bottom;

bottomAxis.Increment = DateTimeSteps.TwoDays;


I get error message "Cannot implicitly convert type 'Steema.TeeChart.DateTimeSteps' to double". An explicit conversion exists.

How would you set up the datetime increment ?

Thanks

James

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

Post by Narcís » Thu Oct 18, 2007 11:49 am

Hi James,

Try something like this:

Code: Select all

      tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);
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

jamesl
Newbie
Newbie
Posts: 10
Joined: Wed May 23, 2007 12:00 am
Contact:

Post by jamesl » Thu Oct 18, 2007 12:25 pm

Hi Narcis

Thanks for the quick reply. That compiles ok. What I notice is that I still see the automatic date/time labels for each piece of data. What I was looking for was, labels for specific increments eg one week apart.
Is there something that switches off auto labels and shows the coded increments.
I've tried

line2.Chart.Axes.Bottom.Automatic = false

but this doesn't seem to work.

Thanks

James

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

Post by Narcís » Thu Oct 18, 2007 1:11 pm

Hi James,

This may happen because you provided labels to the series using LabelMember and therefore the bottom axis automatically uses them. To use XValues as labels you can do this:

Code: Select all

			tChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;
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

jamesl
Newbie
Newbie
Posts: 10
Joined: Wed May 23, 2007 12:00 am
Contact:

Post by jamesl » Mon Oct 22, 2007 7:40 am

Thanks Narcis.
This gives me good flexibilty over the axis - but for some reason I can no longer see the chart line. Axis now spot on, data line not visible. All I want to do is create a line chart at runtime from SQL data table.


strCon = ConfigurationManager.ConnectionStrings["M5ConnectionString"].ConnectionString;
strSelect = "SELECT Net_Total, Invoice_Date FROM et_View_Sales_History WHERE SoldTo_location_Code = \'" + DropDownSortBy.SelectedValue + "\'";

SqlDataAdapter da = new SqlDataAdapter(strSelect, strCon);
DataTable tbl = new DataTable();
da.Fill(tbl);

Steema.TeeChart.Chart Chart2 = WebChartControl1.Chart;

Steema.TeeChart.Styles.Line line2 = new Steema.TeeChart.Styles.Line(Chart2);

line2.XValues.DateTime = true;

Steema.TeeChart.Axis bottomAxis = WebChartControl1.Chart.Axes.Bottom;

bottomAxis.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneMonth);
line2.Chart.Header.Text = "Sales Net / Month";
line2.Chart.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy";
line2.Chart.Axes.Bottom.Labels.Angle = 90;
line2.Chart.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;
line2.Chart.Axes.Bottom.SetMinMax(DateTime.Parse("01/01/2007"), DateTime.Parse("31/12/2007"));

line2.YValues.DataMember = tbl.Columns["Net_Total"].ToString();
line2.LabelMember = tbl.Columns["Invoice_Date"].ToString();
line2.DataSource = tbl;


Funny, but if I note out the line -

line2.Chart.Axes.Bottom.SetMinMax(DateTime.Parse("01/01/2007"), DateTime.Parse("31/12/2007"));

My data line comes back but my bottom axis isn't right.
Any ideas on how to get round this - and/or can you point me to a good example on setting up date/time axis (I've already looked in the tutorials and most of the examples)

Thanks for you help

James

jamesl
Newbie
Newbie
Posts: 10
Joined: Wed May 23, 2007 12:00 am
Contact:

Post by jamesl » Mon Oct 22, 2007 9:15 am

Hi Narcis

Problem solved - my fault :oops:

line2.LabelMember = tbl.Columns["Invoice_Date"].ToString();

needed to be

line2.XValues.DataMember = tbl.Columns["Invoice_Date"].ToString();

Thanks very much for your help, much appreciated.

James

Post Reply