简体   繁体   中英

Labels on Chart Toolkit WPF

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. 在此输入图像描述

When the code for X axis is introduced as:

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

在此输入图像描述

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM