2

我需要区域系列图表看起来像:在此处输入图像描述

我成功地隐藏了两个轴并将颜色更改为渐变画笔。我仍然需要改变不透明度的帮助,所以绿色的将在橙色的“后面”。另外 - 如何更改图表上的小点?如何将背景更改为透明?如何隐藏图表标题?

现在它看起来像这样:

在此处输入图像描述

任何帮助将不胜感激!

这是我的 xaml 代码:

    <LinearGradientBrush x:Key="GreenGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="#77b31a" Offset="0.75"></GradientStop>
            <GradientStop Color="#85d805" Offset="0.45"></GradientStop>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="OrangeGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <LinearGradientBrush.GradientStops>
        <GradientStop Color="#fff92900" Offset="0.75"></GradientStop>
            <GradientStop Color="#ffff6115" Offset="0.45"></GradientStop>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <Style x:Key="GreenAreaSeriesStyle" TargetType="Control">
        <Setter Property="Background" Value="{StaticResource GreenGradientBrush}" />
        <Setter Property="Opacity" Value="1"></Setter>
    </Style>
    <Style x:Key="OrangeAreaSeriesStyle" TargetType="Control">
        <Setter Property="Background" Value="{StaticResource OrangeGradientBrush}" />
        <Setter Property="Opacity" Value="1"></Setter>
    </Style>

    <datavis:ResourceDictionaryCollection x:Key="MyPalette">
        <ResourceDictionary>
            <Style x:Key="DataPointStyle" BasedOn="{StaticResource GreenAreaSeriesStyle}" TargetType="Control" >
            </Style>
        </ResourceDictionary>
        <ResourceDictionary>
            <Style x:Key="DataPointStyle" BasedOn="{StaticResource OrangeAreaSeriesStyle}" TargetType="Control" >
            </Style>
        </ResourceDictionary>
    </datavis:ResourceDictionaryCollection>

    <Style x:Key ="PerformanceChartMajorTickMarkStyle" TargetType="Line">
        <Setter Property="Visibility" Value="Collapsed" />
    </Style>

</Window.Resources>
 <charting:Chart Palette="{StaticResource MyPalette}" HorizontalAlignment="Left" Margin="39,38,0,0" Name="chart1" Title="Chart Title" VerticalAlignment="Top" Width="815" Height="598" OverridesDefaultStyle="False">            
        <charting:Chart.LegendStyle>
                <Style TargetType="datavis:Legend">
                    <Setter Property="Width" Value="0" />
                </Style>
        </charting:Chart.LegendStyle>

        <charting:AreaSeries Name="Green" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}"  IsSelectionEnabled="True" >
            <charting:AreaSeries.IndependentAxis>
                <charting:CategoryAxis Orientation="X" Visibility="Hidden"/>
            </charting:AreaSeries.IndependentAxis>
            <charting:AreaSeries.DependentRangeAxis>
                <charting:LinearAxis Orientation="Y" Visibility="Hidden"/>
            </charting:AreaSeries.DependentRangeAxis>

        </charting:AreaSeries>
        <charting:AreaSeries Name="Orange" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}"  IsSelectionEnabled="True">
            <charting:AreaSeries.IndependentAxis>
                <charting:CategoryAxis Orientation="X" Visibility="Hidden"/>
            </charting:AreaSeries.IndependentAxis>
            <charting:AreaSeries.DependentRangeAxis>
                <charting:LinearAxis Orientation="Y" Visibility="Hidden"/>
            </charting:AreaSeries.DependentRangeAxis>
        </charting:AreaSeries>
    </charting:Chart>
4

1 回答 1

2

我发布了一个类似的问题并得到了以下答案,这对我很有帮助。

<ch:Chart Margin="56,21,50,72" Title="MyChart" DataContext="{Binding ElementName=Window, Mode=OneWay}"  Style="{StaticResource controlStyle}" >

                <ch:AreaSeries Name="DefaultArea" ItemsSource="{Binding Path=Key}" IndependentValueBinding="{Binding Key}" DependentValueBinding="{Binding Value}" Opacity="1" Title="111111" >
                    <ch:AreaSeries.Style>
                        <Style TargetType="ch:AreaSeries">
                            <Setter Property="IsTabStop" Value="False"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ch:AreaSeries">
                                        <Canvas x:Name="PlotArea">
                                            <Path Data="{TemplateBinding Geometry}" StrokeThickness="3" Fill="Pink" Style="{TemplateBinding PathStyle}" Opacity="1" />
                                        </Canvas>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ch:AreaSeries.Style>
                </ch:AreaSeries>

                <ch:AreaSeries Name="PersonnelArea" ItemsSource="{Binding Path=Key}" IndependentValueBinding="{Binding Key}" DependentValueBinding="{Binding Value}" Opacity="1" >
                    <ch:AreaSeries.Style>
                        <Style TargetType="ch:AreaSeries">
                            <Setter Property="IsTabStop" Value="False"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ch:AreaSeries">
                                        <Canvas x:Name="PlotArea">
                                            <Path Data="{TemplateBinding Geometry}" StrokeThickness="3" Fill="Yellow" Style="{TemplateBinding PathStyle}" Opacity="1" />
                                        </Canvas>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ch:AreaSeries.Style>

                </ch:AreaSeries>  
            </ch:Chart>

您还可以在 XAML 中将样式设置为 Ressource,然后在后面的代码中动态分配它。这是我的原始问题的答案: WPF AreaSeries:如何更改背景不透明度?

于 2013-07-24T14:38:47.237 回答