4

Is there any way to label the axis on charts?

<charting:Chart Name="EventAlertsChart" BorderThickness="0" Margin="0,10,0,0">

        <charting:Chart.Axes>
            <charting:LinearAxis Orientation="Y" Minimum="0" Title="Number of Alerts" Margin="0,0,10,0" />
        </charting:Chart.Axes>


        <charting:Chart.LegendStyle>
            <Style TargetType="Control">
                <Setter Property="Width" Value="0" />
                <Setter Property="Height" Value="0" />
            </Style>
        </charting:Chart.LegendStyle>

        <charting:Chart.Series>
            <charting:ColumnSeries Name="LineSeriesBWSrc" ItemsSource="{Binding AlertPoints,UpdateSourceTrigger=PropertyChanged}" 
                    IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}" Title="Alerts" Background="Maroon"  >
                <charting:ColumnSeries.DataPointStyle>
                    <Style TargetType="charting:ColumnDataPoint">
                        <Setter Property="Background" Value="Crimson" />
                    </Style>
                </charting:ColumnSeries.DataPointStyle>
            </charting:ColumnSeries>
        </charting:Chart.Series>
    </charting:Chart>

I've managed to label the Y axis using

<charting:Chart.Axes>
            <charting:LinearAxis Orientation="Y" Minimum="0" Title="Number of Alerts" Margin="0,0,10,0" />
    </charting:Chart.Axes>

however if I want to label the X axis it appears on the top of the chart. I just want to be able to type some legends on the axis like "Time" and "Events" but I cannot find a proper way to do it.

If I do the same on the X axis, then the legend and the values go to the top of the chart. enter image description here

When the code for X axis is introduced as:

<charting:Chart.Axes>
            <charting:LinearAxis Orientation="Y" Minimum="0" Title="Number of Alerts" 

enter image description here

sll
  • 61,540
  • 22
  • 104
  • 156
Manolete
  • 3,431
  • 7
  • 54
  • 92

1 Answers1

5

Not sure I got question right but if you want to show custom content in place of the Axes you can do it in the following way:

<!-- TODO: Define own custom templates for 
     YAxisTitleContentTemplate and XAxisTitleContentTemplate
 -->
<charting:Chart.Axes>
  <charting:LinearAxis Orientation="Y">
     <charting:LinearAxis.Title>
          <ContentControl
                ContentTemplate="{StaticResource YAxisTitleContentTemplate}"/>
     </charting:LinearAxis.Title>
  </charting:LinearAxis>
  <charting:CategoryAxis Orientation="X">
       <charting:CategoryAxis.Title>
             <ContentControl
                    ContentTemplate="{StaticResource XAxisTitleContentTemplate}"/>
       </charting:CategoryAxis.Title>
  </charting:CategoryAxis>
</charting:Chart.Axes>

EDIT: Title for the X Axis only

<charting:Chart.Axes>
       <charting:CategoryAxis Orientation="X" Title="The X Axis Title" />
</charting:Chart.Axes>
sll
  • 61,540
  • 22
  • 104
  • 156
  • Still not clear, so you able to display text but not able to ... ? – sll Nov 22 '11 at 11:24
  • I am able to display data correctly. But I want to display a label for the axis. X axis is "Time" and "Y" axis is "Number of Alerts". – Manolete Nov 22 '11 at 11:40
  • 1
    In your example you assigning a value for Title `Title="Number of Alerts"` is it displayed? – sll Nov 22 '11 at 11:43
  • Yes, but look at the X axis now. – Manolete Nov 22 '11 at 11:44
  • 1
    yep you need to provide the Title for CategoryAxis as well, see my example. X axis is categoryAxis, and you have defined only LinearAxis (Y), is it clear? See EDIT part of my answer – sll Nov 22 '11 at 11:46