Tuesday, October 25, 2011

Getting visible axis in a chart

I was using a template of a chart and wanted my Y-axis to be visible. So far, I only had the lines where numbers were given (e.g. they started at 10 instead of 0). This template had been created a while back by a colleague and I'm still a noob.

In that particular chart, there are pre generated curves that will not change. The scatter data is dynamic and changes whenever we modify the search settings.

Trying with adding Minimum="0" in the LinearAxis for Y in the code below:

<toolkit:Chart.Axes>
     <toolkit:LinearAxis
          Orientation="X"
          Title="{Binding SOMETHING, Source SOMETHING}"
           Minimum="0"
           Maximum="120"
           Interval="10"
           ShowGridLines="False"/>
      <toolkit:LinearAxis
           Orientation="Y"
           Title="{Binding SOMETHING, Source SOMETHING}"      
           Minimum="0"         
           ShowGridLines="True"/>
</toolkit:Chart.Axes>

Results: I got my Y-axis, however the curves were squeezed. Their upper limits were still the same, but their lower limits were increased. They were, obviously, no longer accurate.

I tried a few things, then found something rather simple (isn't it always the case?). The one creating the template had remove a border from the initial template (when you choose to edit a copy). The border is mostly there to give a border for the area within the axis (a border to show a border, who would have guessed...).

It goes like this:

Template
   > Border
     > Grid
        > Grid
           > Border
           > Chart Area
              > Grid
              > Border
That last border is the one that does the trick!
Add a colour to its BorderBrush and put some of the BorderThickness to 0 depending on what result you want. I wanted my X and Y axis, so I used 1, 0, 0, 1, like this:

<Border BorderBrush="Black" BorderThickness="1,0,0,1"/>

No comments:

Post a Comment