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?
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.
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.
© 2022 - 2024 — McMap. All rights reserved.