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 ?
X Axis - Date formatting
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
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!
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 |
Instructions - How to post in this forum |
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
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
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi James,
Try something like this:
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 |
Instructions - How to post in this forum |
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
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
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
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:
Hope this helps!
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;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
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
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