Page 1 of 1

X Axis - Date formatting

Posted: Wed Oct 17, 2007 2:44 pm
by 13045150
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 ?

Posted: Wed Oct 17, 2007 2:59 pm
by narcis
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!

Posted: Thu Oct 18, 2007 11:34 am
by 13045150
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

Posted: Thu Oct 18, 2007 11:49 am
by narcis
Hi James,

Try something like this:

Code: Select all

      tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);

Posted: Thu Oct 18, 2007 12:25 pm
by 13045150
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

Posted: Thu Oct 18, 2007 1:11 pm
by narcis
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!

Posted: Mon Oct 22, 2007 7:40 am
by 13045150
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

Posted: Mon Oct 22, 2007 9:15 am
by 13045150
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