图表工具包 WPF 上的标签

发布于 2024-12-17 12:55:59 字数 2001 浏览 1 评论 0原文

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

<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 轴上执行相同的操作,则图例和值将显示在图表的顶部。 在此处输入图像描述

当 X 轴的代码引入为:

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

在此处输入图像描述

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骷髅 2024-12-24 12:55:59

不确定我的问题是否正确,但如果您想显示自定义内容来代替轴,您可以通过以下方式执行此操作:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文