如何在LineChart上进行更改

时间:2016-09-01 13:48:18

标签: uwp winrt-xaml winrt-xaml-toolkit

我在下面尝试过它并没有用。

IValidationContext

如何

1)更改IndependentValuePath和DependentValuePath的fontsize?以上不起作用。
 2)更改IndependentValuePath和DependentValuePath的颜色?以上不起作用。
 3)当触摸折线图的直线或点时,如何获取IndependentValuePath和DependentValuePath的值?

------- Edit_2

<Charting:LineSeries Title="Line_1" Margin="0" 
FontSize="30" Tapped="LineSeries_Tapped" 
FontWeight="SemiBold"   BorderBrush="Red"  
IndependentValuePath="interval" 
DependentValuePath="size" IsSelectionEnabled="True">

 </Charting:Chart>

与(1)和(2)我得到了点和中风。

由于

2 个答案:

答案 0 :(得分:0)

首先,对于LineSeries元素,您要更改样式的两个属性是DependentValueBindingIndependentValueBinding

  

1)更改IndependentValuePath和DependentValuePath的fontsize?以上不起作用。

对于IndependentValueBinding属性的样式,它由LineSeries父元素Chart定义,因此直接为fontsize设置LineSeris属性元素将不起作用。设置图表元素的Fontsize将起作用。

<charting:Chart
   x:Name="LineChart"
   Title="Line Chart"
   Margin="70,0" 
   FontSize="30">

对于DependentValueBinding属性,它实际上是PolyLine,不具有FontSize属性。

  

2)更改IndependentValuePath和DependentValuePath的颜色?以上不起作用。

对于IndependentValueBinding的颜色,它与fontsize属性相同,只为Foreground元素设置Chart属性。 对于DependentValueBinding的颜色,它应该更改在LineSeries的ControlTemplate中的PolyLine的颜色。更改Stroke的{​​{1}}属性将起作用。

PolyLine
  

3)当触摸折线图的直线或点时,如何获取IndependentValuePath和DependentValuePath的值?

在点击事件中,获取所选项目并获取绑定到<charting:LineSeries.Style> <Style TargetType="charting:LineSeries"> <Setter Property="IsTabStop" Value="False" /> <Setter Property="PolylineStyle"> <Setter.Value> <Style TargetType="Polyline"> <Setter Property="StrokeThickness" Value="10" /> <Setter Property="StrokeMiterLimit" Value="1" /> </Style> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="charting:LineSeries"> <Canvas x:Name="PlotArea"> <Polyline Style="{TemplateBinding PolylineStyle}" Stroke="Red" Points="{TemplateBinding Points}" /> </Canvas> </ControlTemplate> </Setter.Value> </Setter> </Style> </charting:LineSeries.Style> IndependentValueBinding属性的值。

DependentValueBinding

以下是包含上述功能的完整代码,请尝试按上述方式设置属性。

Xaml Code

if (line1.SelectedItem != null)
{
    NameValueItem seleteditem = line1.SelectedItem as NameValueItem;
    System.Diagnostics.Debug.WriteLine(seleteditem.Name);
    System.Diagnostics.Debug.WriteLine(seleteditem.Value);
}

背后的代码

<charting:Chart
    x:Name="LineChart"
    Title="Line Chart"
    Margin="70,0"
    Foreground="Red"
    FontSize="30">
    <charting:LineSeries
        x:Name="line1"
        Title="Population in 2005"
        DependentValueBinding="{Binding Value}"
        IndependentValueBinding="{Binding Name}"
        IsSelectionEnabled="True"
        Tapped="LineSeries_Tapped">
        <charting:LineSeries.Style>
            <Style TargetType="charting:LineSeries">
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="PolylineStyle">
                    <Setter.Value>
                        <Style TargetType="Polyline">
                            <Setter Property="StrokeThickness" Value="10" />
                            <Setter Property="StrokeMiterLimit" Value="1" />
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="charting:LineSeries">
                            <Canvas x:Name="PlotArea">
                                <Polyline
                                    Style="{TemplateBinding PolylineStyle}"
                                    Stroke="Red"
                                    Points="{TemplateBinding Points}" />
                            </Canvas>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </charting:LineSeries.Style>
    </charting:LineSeries>     
</charting:Chart>

答案 1 :(得分:0)

为了使点更大,您可以更新LineDataPoint样式,如下所示。更改WidthHeight属性将起作用。控件模板中Ellipse的WidthHeight已定义属性。

<charting:Chart
        x:Name="LineChart"
        Title="Line Chart"
        Margin="70,0"
        Foreground="Red"
        FontSize="10">
        <charting:LineSeries
            x:Name="line1"
            Title="Population in 2005"
            DependentValueBinding="{Binding Value}"
            IndependentValueBinding="{Binding Name}"
            IsSelectionEnabled="True"
            Tapped="LineSeries_Tapped" >
            <charting:LineSeries.DataPointStyle>
                <Style TargetType="charting:LineDataPoint"> 
                    <Setter Property="Width" Value="20" />
                    <Setter Property="Height" Value="20" />                      
                </Style>
            </charting:LineSeries.DataPointStyle>
        </charting:LineSeries>
    </charting:Chart>