Chart Toolkit WPF上的标签

时间:2011-11-22 10:41:40

标签: c# wpf charts wpftoolkit

有没有办法在图表上标记轴?

<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>

我已设法使用

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

但是,如果我想标记X轴,它会出现在图表的顶部。我只是想在轴上输入一些类似“时间”和“事件”的图例,但我找不到合适的方法。

如果我在X轴上执行相同操作,则图例和值将显示在图表的顶部。 enter image description here

当X轴的代码被引入为:

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

            

enter image description here

1 个答案:

答案 0 :(得分:5)

我不确定我是否有问题,但如果您想显示自定义内容而不是Axes,您可以通过以下方式进行:

<!-- 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>

编辑:仅X轴的标题

<charting:Chart.Axes>
       <charting:CategoryAxis Orientation="X" Title="The X Axis Title" />
</charting:Chart.Axes>