I have a series on the xamDataChart that is being rendered properlu on the Y1 axis, but if I select the Y2 axis, the axis stroke is on the wrong side of the screen. The only difference between the two axis is the Label settings which state which side of the graph labels should be located.
So what am I doing wrong?
And Here is my axis initialization code. Note the underlined section is the only difference between my Y1 axis code and my Y2 axis code.
private void axisInitialization(){ AxisLabelSettings rightAxisSettings = new AxisLabelSettings(); TitleSettings y2AxisTitleSettings = new TitleSettings(); SolidColorBrush axisBrush = new SolidColorBrush(Colors.Black); SolidColorBrush transparentBrush = new SolidColorBrush(Colors.Transparent);
y2AxisTitleSettings.Foreground = axisBrush; y2AxisTitleSettings.FontFamily = new FontFamily("Segoe UI"); y2AxisTitleSettings.Angle = -90; rightAxisSettings.FontFamily = new FontFamily("Segoe UI"); rightAxisSettings.Foreground = axisBrush; rightAxisSettings.Margin = new Thickness(5); rightAxisSettings.Location = AxisLabelsLocation.OutsideRight; numericY2Axis.TickLength = 7; numericY2Axis.MajorStroke = transparentBrush; numericY2Axis.TickStroke = axisBrush; numericY2Axis.Stroke = axisBrush; numericY2Axis.Name = "y2Axis"; numericY2Axis.Label = "{:E2}"; numericY2Axis.LabelSettings = rightAxisSettings; numericY2Axis.TitleSettings = y2AxisTitleSettings; numericY2Axis.Visibility = Visibility.Visible; AxisCollection.Add(numericY2Axis); }
Hi Ed,
Try setting the CrossingAxis property on the Y axis to point at the X axis:
numericY2Axis.CrossingAxis = myXAxis;
Then set the CrossingValue property to equal the number of data points in your X axis ItemsSource collection.
numericY2Axis.CrossingValue = data.Count;
But this won't work if my X axis is a category axis like the CategoryDateTimeXAxis. So what am i supposed to do about that?
Thanks, that did the trick!
Ed
The same thing still applies. Instead of using the total number of data points as the crossing value, use the maximum visible date. You can bind to it like this:
numericY2Axis.SetBinding(NumericYAxis.CrossingValueProperty, new Binding("ActualMaximumValue.Ticks") { Source = xAxis });