Force axis to use given number of major tick marks in Visiblox chart
Asked Answered
M

2

5

When using a LinearAxis for the Y axis in a Visiblox chart, I would like to force the axis to use a given number of major tick marks while still having the toolkit automatically calculate the axis range and tick mark locations. For instance, I may have a primary and secondary Y axis and I want both axes to use the same number of major ticks so that their horizontal gridlines overlap. Is this possible?

Mulry answered 21/7, 2011 at 18:48 Comment(0)
K
4

There are a couple of options. Firstly you can set the MajorTickInterval to force the distribution of major ticks. Depending on your use-case you may need to look at the actual range of the axis, and divide by the number of ticks you want to get a sensible interval.

The other alternative is to subclass the axis and override the GetMajorTickValues method which is what the axis uses to determine where to place ticks.

Kirimia answered 22/7, 2011 at 7:22 Comment(0)
D
4

If you need to enforce a relationship between the values on your primary and secondary axis, this can be achieved via ElementName binding. For example, you can bind the secondary axis MajorTickInterval to the computed tick interval of the primary axis, ActualMajorTickInterval as follows:

<Grid x:Name="LayoutRoot" Background="White">
  <vis:Chart x:Name="chart">
    <vis:Chart.YAxis>
      <vis:LinearAxis x:Name="primaryAxis"/>
    </vis:Chart.YAxis>
    <vis:Chart.SecondaryYAxis>
      <vis:LinearAxis MajorTickInterval="{Binding ElementName=primaryAxis, Path=ActualMajorTickInterval}"/>
    </vis:Chart.SecondaryYAxis>
  </vis:Chart>
</Grid>

However, depending ion your data, having the same tick interval for each axis may not cause your major tick gridlines to coincide. In this case, you might want to bind the range alse:

<Grid x:Name="LayoutRoot" Background="White">
  <vis:Chart x:Name="chart">
    <vis:Chart.YAxis>
      <vis:LinearAxis x:Name="primaryAxis"/>
    </vis:Chart.YAxis>
    <vis:Chart.SecondaryYAxis>
      <vis:LinearAxis Range="{Binding ElementName=primaryAxis, Path=ActualRange}"
                      MajorTickInterval="{Binding ElementName=primaryAxis, Path=ActualMajorTickInterval}"/>
    </vis:Chart.SecondaryYAxis>
  </vis:Chart>
</Grid>

If you need more complex logic, it might be possible to do this via value converters.

Duroc answered 22/7, 2011 at 7:56 Comment(1)
Thanks for the example, however, this isn't quite what I was thinking of. In my situation, it could be that data on one axis ranges from 0 to 1 and on the other from 10,000 to 15,000. The goal then is not to do binding on absolute tick intervals or ranges, but rather just to force the secondary axis to draw a nice set of ticks with the condition that a given number of ticks be used. I also cannot take the default range and divide by the number of ticks I want, because then the tick locations may not be "pretty". Perhaps the only way here is to rewrite the tick positioning algorithm.Mulry

© 2022 - 2024 — McMap. All rights reserved.