I'd like my axes to display as I have shown in red, however, I'm unable to do so. Any help is greatly appreciated. Code below.
CategoryDateTimeXAxis xAxis = new CategoryDateTimeXAxis(); NumericYAxis yAxis = new NumericYAxis(); NumericYAxis yAxisRight = new NumericYAxis(); xAxis.DataSource = columnData; xAxis.DateTimeMemberPath = "CategoryDate"; xAxis.Label = "CategoryDate"; xAxis.FormatLabel += xAxis_FormatLabel; yAxisRight.FormatLabel += yAxisRight_FormatLabel; yAxis.FormatLabel += yAxis_FormatLabel; xAxis.LabelAngle = 90; xAxis.Gap = 10; yAxisRight.LabelLocation = AxisLabelsLocation.OutsideRight; yAxisRight.LabelTextColor = new Infragistics.Win.DataVisualization.SolidColorBrush(Color.Green); chart.Axes.Clear(); chart.Series.Clear(); chart.Axes.Add(xAxis); chart.Axes.Add(yAxisRight); chart.Axes.Add(yAxis); ColumnSeries columnSeries = new ColumnSeries(); columnSeries.DataSource = columnData; columnSeries.Title = "Actual Billed Hours / Day"; columnSeries.ValueMemberPath = "Value"; columnSeries.XAxis = xAxis; columnSeries.YAxis = yAxisRight; LineSeries lineSeries = new LineSeries(); lineSeries.DataSource = lineData; lineSeries.Title = "Revenue Per Hour"; lineSeries.ValueMemberPath = "Value"; lineSeries.XAxis = xAxis; lineSeries.YAxis = yAxis; lineSeries.Brush = new Infragistics.Win.DataVisualization.SolidColorBrush(Color.Green); if (legend == null) { legend = new UltraLegend(); legend.Name = "Legend"; legend.BackColor = Color.Transparent; frm.Controls.Add(legend); legend.Left = 370; legend.Top = 58; legend.BringToFront(); } chart.Series.Add(columnSeries); chart.Series.Add(lineSeries); chart.Refresh(); chart.Legend = legend;
Hi Phil,
I think what you are looking for is the DisplayType property. My guess it is set to the default for a DateTime Axis of continuous. For how you want it displayed you would want the Discrete. Try this out and let me know if it helps.xAxis.DisplayType = TimeAxisDisplayType.Discrete;
That aligned each label in the center of the column as desired. However, it's changed ALL the column labels to "Jan/0001" instead of "Nov/2014", "Dec/2014", "Jan/2015" etc... Any thoughts on why that is?
This does appear to be a incorrect behavior, that I will log and make sure is addressed. That being said there are a few workarounds for it for your scenario. First, just because you have datetime data, doesn't mean you need to use a CategoryDateTimeAxis, you can use a CategoryAxis. Especially if you want the data to display discreetly, a normal CategoryAxis is actually the preferred practice. Second if you want to still use the CategoryDateTimeAxis, you can but you will need to handle the FormatLabel event on the CategoryDateTimeAxis. You will notice that behavior clearly here as well in that in the event args, the info.DateValue is returning 1/1/01. You will need to use your item and get the date value from that.
Let me know if the workarounds work for you,
I received back from the developer on this issue that this behavior isn't a bug, here is the reason they gave:When the CategoryDateTimeAxis DisplayType is set to Continuous, the label text is basically calculated by adding the interval multiplied by the label index to the actual minimum value of the axis. The date that is the result from this calculation is passed to the method that fires the FormatLabel event and is assigned to the DateValue property of the event arguments. However when the DisplayType is set to Discrete this is no longer possible since we need to align the labels with the corresponding values and we don’t know what the intervals between the values will be. So in order to get the labels in this case we use the items from the data source. This time the underlying object is passed to the method that raises FormatLabel (in the testbed it is of type ValulessDateCategoryItem). This object is no longer a date so we can’t assign it to the DateValue property of the event arguments, it actually gets assigned to the event argument’s Item property. The testbed tries to FormatLabel event returns the DateValue regardless if it has one or not. In the case of Discrete DisplayType it returns a default date (DateTime.Min). As such hopefully the workarounds I gave earlier, specifically using a CategoryAxis, or handling FormatLabel worked in your scenario.