Hello. I'm using NET Advantage 10.2
I have a Column chart which takes 2 funds' performance data from SQL DB.
It works fine, but the X Axis label displays long date/time instead of formatted short time. I use this Markup in ASPX file: ItemFormatString="<ITEM_LABEL:MMM-yy>"
And also in .CS file:
this.chPerformance.Axis.X.Labels.ItemFormat = Infragistics.UltraChart.Shared.Styles.AxisItemLabelFormat.Custom; this.chPerformance.Axis.X.Labels.ItemFormatString = "<ITEM_LABEL:MMM-yy>";
But the labels still come out as on the attached picture.
I'm binding data to the chart like this:
DataTable perftable = new DataTable(); perftable.Columns.Add(new DataColumn("Date", typeof(System.DateTime))); perftable.Columns.Add(new DataColumn("Fund1", typeof(System.Double))); perftable.Columns.Add(new DataColumn("Fund2", typeof(System.Double))); foreach (DateTime dt in dates) { double p1 = fund.TimeSeries[dt] == null ? 0 : fund.TimeSeries[dt].PercentChange; double p2 = otherfund.TimeSeries[dt] == null ? 0 : otherfund.TimeSeries[dt].PercentChange; perftable.Rows.Add(new object[] { dt, p1, p2 }); } this.chPerformance.Data.DataSource = perftable; this.chPerformance.DataBind(); Please advise on how to format the X axis labels to display MMM-YY Thanks a lot.
DataTable perftable = new DataTable(); perftable.Columns.Add(new DataColumn("Date", typeof(System.DateTime))); perftable.Columns.Add(new DataColumn("Fund1", typeof(System.Double))); perftable.Columns.Add(new DataColumn("Fund2", typeof(System.Double))); foreach (DateTime dt in dates) { double p1 = fund.TimeSeries[dt] == null ? 0 : fund.TimeSeries[dt].PercentChange; double p2 = otherfund.TimeSeries[dt] == null ? 0 : otherfund.TimeSeries[dt].PercentChange; perftable.Rows.Add(new object[] { dt, p1, p2 }); } this.chPerformance.Data.DataSource = perftable; this.chPerformance.DataBind();
Please advise on how to format the X axis labels to display MMM-YY
Thanks a lot.
The column chart doesn’t accept DateTime values as X-values. It accepts them like strings, for that you can’t format them. In your case you can change the type of the first column to be typeof(string) and add the rows with:
perftable.Rows.Add(new object[] { dt.ToString("MMM-yy"), p1, p2 });
That did the trick, thanks a lot, Teodor