WPF,图表控件

开源代码地址:https://github.com/bearhanQ/WPFFramework;

QQ群:332035933;

<UserControl x:Class="WpfBootstrap.View.ChartsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfBootstrap.View"
             xmlns:s="clr-namespace:System;assembly=mscorlib"
             xmlns:m="clr-namespace:WpfBootstrap.Model"
             xmlns:cc="clr-namespace:WPFTemplate;assembly=WPFTemplate"
             xmlns:p="clr-namespace:WpfBootstrap.Common"
             xmlns:vws="clr-namespace:WpfBootstrap.View"
             mc:Ignorable="d"
             d:DesignHeight="600" d:DesignWidth="400">
    <UserControl.Resources>
        <x:Array x:Key="revenueInfo" Type="{x:Type m:Revenue}">
            <m:Revenue Day="周一" Value="1000000"/>
            <m:Revenue Day="周二" Value="1500000"/>
            <m:Revenue Day="周三" Value="2000000"/>
            <m:Revenue Day="周四" Value="5000000"/>
            <m:Revenue Day="周五" Value="2500000"/>
            <m:Revenue Day="周六" Value="3000000"/>
            <m:Revenue Day="周七" Value="1000000"/>
        </x:Array>
        <p:BarValueWarningConverter x:Key="BarValueWarningConverter"/>
        <Style x:Key="barStyle1" TargetType="{x:Type cc:Bar}">
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="{x:Type cc:BarItem}" BasedOn="{StaticResource {x:Type cc:BarItem}}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Value,Converter={StaticResource BarValueWarningConverter},ConverterParameter=2000000}" Value="True">
                                <DataTrigger.Setters>
                                    <Setter Property="Background" Value="#FFF4D505"/>
                                </DataTrigger.Setters>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Value,Converter={StaticResource BarValueWarningConverter},ConverterParameter=3000000}" Value="True">
                                <DataTrigger.Setters>
                                    <Setter Property="Background" Value="Red"/>
                                </DataTrigger.Setters>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <cc:CornerScrollViewer>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="300"/>
                <RowDefinition Height="300"/>
                <RowDefinition Height="300"/>
            </Grid.RowDefinitions>
            <cc:Bar ItemsSource="{StaticResource revenueInfo}" ValueMemberPath="Value" DisplayMemberPath="Day" Style="{StaticResource barStyle1}"/>
            <cc:Donut ItemsSource="{StaticResource revenueInfo}" ValueMemberPath="Value" DisplayMemberPath="Day"
                  Grid.Column="1" ArcThickness="60" Orientation="Vertical"/>
            <cc:LineChart Grid.Row="1" ItemsSource="{StaticResource revenueInfo}" DisplayMemberPath="Day" ValueMemberPath="Value" OpenAnimation="False"/>
            <cc:CurveChart Grid.Row="1" Grid.Column="1" ItemsSource="{StaticResource revenueInfo}" 
                       DisplayMemberPath="Day" ValueMemberPath="Value" OpenAnimation="False"
                       Stroke="Red"/>
            <cc:StepChart Grid.Row="2" ItemsSource="{StaticResource revenueInfo}" Stroke="#FF0CFF00"
                      DisplayMemberPath="Day" ValueMemberPath="Value" OpenAnimation="False"/>
        </Grid>
    </cc:CornerScrollViewer>
</UserControl>

  

    public class Revenue
    {
        public string Month { get; set; }
        public string Day { get; set; }
        public string Profits { get; set; }
        public int Value { get; set; }
    }

 

posted @ 2024-06-06 16:01  BearHan  阅读(217)  评论(0)    收藏  举报