如何在LiveCharts中显示轴部分工具提示和重新定位数据标签

时间:2017-07-17 21:15:12

标签: c# wpf livecharts

1)我希望在LiveCharts中显示轴部分的工具提示,但似乎无法弄清楚如何操作。以下是我目前使用LiveCharts的代码。

        <Grid Grid.Column="1" Margin="15, 15, 15, 15" MaxHeight="500">
        <Grid.OpacityMask>
            <VisualBrush Visual="{Binding ElementName=Border}" />
        </Grid.OpacityMask>
        <Grid.Resources>
            <Style TargetType="lvc:LineSeries">
                <Setter Property="Stroke" Value="Black"/>
                <Setter Property="LineSmoothness" Value="0"/>
                <Setter Property="Fill" Value="Transparent"/>
                <Setter Property="PointForeground" Value="White"/>
            </Style>
            <Style TargetType="lvc:Axis">
                <Setter Property="ShowLabels" Value="True"/>
                <Setter Property="Foreground" Value="White"/>
            </Style>
            <Style TargetType="lvc:Separator">
                <Setter Property="Stroke" Value="DimGray"/>
                <Setter Property="StrokeDashArray" Value="2"/>
                <Setter Property="IsEnabled" Value="True"/>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Border x:Name="Border" Grid.Row="0" Grid.RowSpan="3" CornerRadius="5" Background="Gray"/>
        <TextBlock Grid.Row="0" TextAlignment="Center" Padding="10, 10, 0, 5" Foreground="Black" FontSize="24" FontWeight="Bold">
                Process Capability
        </TextBlock>
        <TextBlock Grid.Row="1" TextAlignment="Center" Foreground="Black" Padding="0,0,0,20">Sample Values</TextBlock>
        <lvc:CartesianChart Series="{Binding SeriesCollection}" Grid.Row="2" Margin="0, 0, 0, 0" Foreground="Black" Zoom="X">
            <lvc:CartesianChart.AxisY>
                <lvc:Axis Name="Y" MinValue="{Binding MinimumY}" MaxValue="{Binding MaximumY}" LabelFormatter="{Binding Formatter}">
                    <lvc:Axis.Sections>
                        <lvc:AxisSection Value="{Binding LowerSpecificationLimit}" StrokeThickness="3" Stroke="Black" DataLabel="True" ToolTip="HELLOOOO" Panel.ZIndex="99"/>
                        <lvc:AxisSection Value="{Binding UpperSpecificationLimit}" StrokeThickness="3" Stroke="Black" DataLabel="True" ToolTip="{Binding LowerSpecificationLimitToolTip}"/>
                        <lvc:AxisSection Value="{Binding NominalConstraint}" StrokeThickness="1.5" Stroke="DarkGray" DataLabel="True" StrokeDashArray="5" ToolTip="{Binding LowerSpecificationLimitToolTip}"/>
                        <lvc:AxisSection Value="{Binding LowerTolerance}" StrokeThickness="1.5" Stroke="DarkGray" DataLabel="True" StrokeDashArray="5" ToolTip="{Binding LowerSpecificationLimitToolTip}"/>
                        <lvc:AxisSection Value="{Binding UpperTolerance}" StrokeThickness="1.5" Stroke="DarkGray" DataLabel="True" StrokeDashArray="5" ToolTip="{Binding LowerSpecificationLimitToolTip}"/>
                    </lvc:Axis.Sections>
                </lvc:Axis>
            </lvc:CartesianChart.AxisY>
        </lvc:CartesianChart>
    </Grid>

2)我还希望能够改变DataLabel的位置。在下图中,您可以看到Axis Section数据标签与常规轴的数据标签重叠。为了防止它重叠,我想将轴部分的数据标签放在图表的右侧而不是左侧。 Image

感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:1)

对于第二个问题,使用合并轴可能有所帮助。 (将true属性设置为mysqlnd。)

参考:https://lvcharts.net/App/examples/v1/wpf/Axes