博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF 自定义BarChartControl(可左右滑动的柱状图)
阅读量:6925 次
发布时间:2019-06-27

本文共 36204 字,大约阅读时间需要 120 分钟。

自定义可左右滑动、拖拽滑动的平面柱状图

 

在做这种样式控件之前,可先浏览我之前预研的控件:

A、

B、

 OK,现在说下控件具体设计过程:

1)采用Grid布局,这样可以将Y轴的标题设置平均高度,X轴的柱子也可以平均。

  当然X轴也会存在一个问题,当数据较少时,只有俩个柱子难道就布满界面?

  很简单,在Grid中多添加一个ColumnDefinition就行了,柱子的宽度设置成可配置,额外的一个设置成默认填充。

2)Bar采用RadioButton,因为有Checked属性,之后整个控件SelectionChanged的事件源可以从这来

3)滑动条容器,我这边比较熟悉DevExpress控件,所以用的是ScrollBox,然后修改其中的模板。

其它的一些设置比较简单,就不说了,直接看代码

 

1、UserControl界面

View Code

2、UserControl后台

public partial class BarChartControl : UserControl    {        public BarChartControl()        {            InitializeComponent();        }        public Brush BorderBrush        {            get { return (Brush)GetValue(BorderBrushProperty); }            set { SetValue(BorderBrushProperty, value); }        }        public static readonly DependencyProperty BorderBrushProperty = DependencyProperty.Register("BorderBrush",        typeof(Brush), typeof(BarChartControl),        new PropertyMetadata(Brushes.Black));        public Thickness BorderThickness        {            get { return (Thickness)GetValue(BorderThicknessProperty); }            set { SetValue(BorderThicknessProperty, value); }        }        public static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register("BorderThickness",        typeof(Thickness), typeof(BarChartControl),        new PropertyMetadata(new Thickness(1.0, 0.0, 1.0, 1.0)));        public AxisYModel AxisY        {            get { return (AxisYModel)GetValue(AxisYProperty); }            set { SetValue(AxisYProperty, value); }        }        public static readonly DependencyProperty AxisYProperty = DependencyProperty.Register("AxisY",        typeof(AxisYModel), typeof(BarChartControl),        new PropertyMetadata(new AxisYModel()));        public AxisXModel AxisX        {            get { return (AxisXModel)GetValue(AxisXProperty); }            set { SetValue(AxisXProperty, value); }        }        public static readonly DependencyProperty AxisXProperty = DependencyProperty.Register("AxisX",        typeof(AxisXModel), typeof(BarChartControl),        new PropertyMetadata(new AxisXModel()));        public double HeaderHeight        {            get { return (double)GetValue(HeaderHeightProperty); }            set { SetValue(HeaderHeightProperty, value); }        }        public static readonly DependencyProperty HeaderHeightProperty = DependencyProperty.Register("HeaderHeight",        typeof(double), typeof(BarChartControl), new PropertyMetadata(10.0));        public string Header        {            get { return (string)GetValue(HeaderProperty); }            set { SetValue(HeaderProperty, value); }        }        public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header",        typeof(string), typeof(BarChartControl), new PropertyMetadata());        private void BarChartControl_OnLoaded(object sender, RoutedEventArgs e)        {            MainBorder.BorderBrush = BorderBrush;            MainBorder.BorderThickness = BorderThickness;            HeaderGrid.Height = HeaderHeight;            MainBarContent.Height = MyScrollBoxFrom0To1.ActualHeight - 17;            LeftGrid.Width = AxisY.Width;            SetYTitlesContent();            SetXDatasContent();        }        private void SetXDatasContent()        {            var axisXModel = AxisX;            if (axisXModel.Datas.Count > 0)            {                int count = axisXModel.Datas.Count;                double barArea = axisXModel.BarWidth + axisXModel.MarginWidth * 2;                for (int i = 0; i < count + 1; i++)                {                    MainBarContent.ColumnDefinitions.Add(new ColumnDefinition()                    {                        Width = new GridLength(barArea)                    });                }                int index = 0;                foreach (var data in axisXModel.Datas)                {                    //主内容                    var stackPanel = new StackPanel();                    stackPanel.Orientation = Orientation.Vertical;                    var tbl = new TextBlock();                    tbl.Height = 15;                    tbl.Text = data.Value.ToString();                    tbl.Foreground = axisXModel.ForeGround;                    tbl.HorizontalAlignment = HorizontalAlignment.Center;                    stackPanel.Children.Add(tbl);                    var radioButton = new RadioButton();                    radioButton.Template = (ControlTemplate)this.Resources["LightedBtnTemplate"];                    radioButton.Width = axisXModel.BarWidth;                    double maxValue = AxisY.Titles.Max(i => i.Value);                    radioButton.Height = (data.Value / maxValue) * (this.ActualHeight - BottomGrid.Height - HeaderHeight + 10);                    var linearBrush = new LinearGradientBrush()                    {                        StartPoint = new Point(1, 0),                        EndPoint = new Point(1, 1),                        GradientStops = new GradientStopCollection() {                                             new GradientStop()                                            {                                                Color = data.FillBrush, Offset = 0                                            }, new GradientStop()                                            {                                                Color = data.FillEndBrush, Offset = 1                                            }                                        }                           };                    radioButton.Background = linearBrush;                    radioButton.HorizontalAlignment = HorizontalAlignment.Center;                    radioButton.Click += RadioButton_OnClick;                    stackPanel.Children.Add(radioButton);                    //底部                    var bottomTbl = new TextBlock();                    bottomTbl.Text = data.Name;                    bottomTbl.Foreground = axisXModel.ForeGround;                    bottomTbl.VerticalAlignment = VerticalAlignment.Center;                    bottomTbl.TextAlignment = TextAlignment.Center;                    bottomTbl.HorizontalAlignment = HorizontalAlignment.Center;                    double textBlockWidth = axisXModel.LabelWidth;                    bottomTbl.Width = axisXModel.LabelWidth;                    stackPanel.Children.Add(bottomTbl);                    Grid.SetColumn(stackPanel, index);                    stackPanel.Margin = new Thickness(0, 0, -textBlockWidth / 2, -17);                    stackPanel.VerticalAlignment = VerticalAlignment.Bottom;                    stackPanel.HorizontalAlignment = HorizontalAlignment.Right;                    MainBarContent.Children.Add(stackPanel);                    MainBarContent.Background = Brushes.Transparent;                    index++;                }                double mainBarContentWidth = count * barArea;                if (mainBarContentWidth > MainGridFrom0To1Content.ActualWidth)                {                    BtnLeft.Visibility = Visibility.Visible;                    BtnRight.Visibility = Visibility.Visible;                }            }        }        public delegate void BarSelectionChangedEventArgs(object sender, RoutedEventArgs e);        public event BarSelectionChangedEventArgs BarSelectionChanged;        private void RadioButton_OnClick(object sender, RoutedEventArgs e)        {            var currentButton = sender as RadioButton;            foreach (var element in MainBarContent.Children)            {                var stackPanel = element as StackPanel;                var button = stackPanel.Children[1] as RadioButton;                if (button != currentButton)                {                    button.IsChecked = false;                }            }            if (BarSelectionChanged!=null)            {                BarSelectionChanged(sender, e);            }        }        private void SetYTitlesContent()        {            var axisYModel = AxisY;            if (axisYModel.Titles.Count > 0)            {                int gridRows = axisYModel.Titles.Count - 1;                for (int i = 0; i < gridRows; i++)                {                    LeftGrid.RowDefinitions.Add(new RowDefinition());                    MainGridForRow1.RowDefinitions.Add(new RowDefinition());                }                int index = 0;                foreach (var title in axisYModel.Titles)                {                    var textblock = new TextBlock();                    textblock.Text = title.Name;                    textblock.Foreground = axisYModel.ForeGround;                    textblock.HorizontalAlignment = HorizontalAlignment.Right;                    textblock.Height = axisYModel.LabelHeight;                    if (index < gridRows)                    {                        textblock.VerticalAlignment = VerticalAlignment.Bottom;                        textblock.Margin = new Thickness(0, 0, 5, -axisYModel.LabelHeight / 2);//因为设置在行底部还不够,必须往下移                        Grid.SetRow(textblock, gridRows - index - 1);                    }                    else                    {                        textblock.VerticalAlignment = VerticalAlignment.Top;                        textblock.Margin = new Thickness(0, -axisYModel.LabelHeight / 2, 5, 0);//最后一个,设置在顶部                        Grid.SetRow(textblock, 0);                    }                    LeftGrid.Children.Add(textblock);                    var border = new Border();                    border.Height = axisYModel.LineHeight;                    border.BorderBrush = axisYModel.LineBrush;                    double thickness = Convert.ToDouble(axisYModel.LineHeight) / 2;                    border.BorderThickness = new Thickness(0, thickness, 0, thickness);                    if (index < gridRows)                    {                        border.VerticalAlignment = VerticalAlignment.Bottom;                        border.Margin = new Thickness(0, 0, 0, -thickness);//因为设置在行底部还不够,必须往下移                        Grid.SetRow(border, gridRows - index - 1);                    }                    else                    {                        border.VerticalAlignment = VerticalAlignment.Top;                        border.Margin = new Thickness(0, -thickness, 0, 0);//最后一个,设置在顶部                        Grid.SetRow(border, 0);                    }                    Grid.SetColumn(border, 0);                    Grid.SetColumnSpan(border, AxisX.Datas.Count + 1);                    MainGridForRow1.Children.Add(border);                    index++;                }            }        }        ///         /// 设置分行        ///         ///         ///         private void SetGridRowDefinitions(Grid leftGrid, int count)        {            for (int i = 0; i < count; i++)            {                leftGrid.RowDefinitions.Add(new RowDefinition());            }        }        ///         /// 向左滑动        ///         ///         ///         private void BtnLeft_OnClick(object sender, RoutedEventArgs e)        {            var startOffset = MyScrollBoxFrom0To1.HorizontalOffset;            if (startOffset <= _lastHorizontalOffset)            {                MyScrollBoxFrom0To1.HorizontalOffset = startOffset - 100;                _lastHorizontalOffset = startOffset - 100;            }            else if (startOffset > _lastHorizontalOffset)            {                BtnLeft.Opacity = 0.5;            }            BtnRight.Opacity = 1;        }        private double _lastHorizontalOffset = 0;        ///         /// 向右滑动        ///         ///         ///         private void BtnRight_OnClick(object sender, RoutedEventArgs e)        {            var startOffset = MyScrollBoxFrom0To1.HorizontalOffset;            if (startOffset >= _lastHorizontalOffset)            {                MyScrollBoxFrom0To1.HorizontalOffset = startOffset + 100;                _lastHorizontalOffset = startOffset + 100;            }            else if (startOffset < _lastHorizontalOffset)            {                BtnRight.Opacity = 0.5;            }            BtnLeft.Opacity = 1;        }    }    #region XDataModel    public class AxisXModel    {        private double _labelWidth = 20;        ///         /// 底部标签-单个宽度        ///         public double LabelWidth        {            get { return _labelWidth; }            set { _labelWidth = value; }        }        private double _marginWidth = 20;        ///         /// Bar间隔宽度        ///         public double MarginWidth        {            get { return _marginWidth; }            set { _marginWidth = value; }        }        private double _height = 20;        ///         /// 高度        ///         public double Height        {            get            {                return _height;            }            set { _height = value; }        }        private Brush _foreGround = Brushes.Black;        ///         /// 字体颜色        ///         public Brush ForeGround        {            get { return _foreGround; }            set { _foreGround = value; }        }        private double _barWidth = 30;        ///         /// Bar宽度        ///         public double BarWidth        {            get { return _barWidth; }            set { _barWidth = value; }        }        List
_datas = new List
(); ///
/// 数据 /// public List
Datas { get { return _datas; } set { _datas = value; } } } public class AxisXDataModel : DataModel { private Color _fillBrush = Colors.Blue; ///
/// Bar填充颜色 /// public Color FillBrush { get { return _fillBrush; } set { _fillBrush = value; } } private Color _fillEndBrush = Colors.Blue; public Color FillEndBrush { get { return _fillEndBrush; } set { _fillEndBrush = value; } } } #endregion #region YDataModel public class AxisYModel { private double _width = 20; ///
/// 宽度 /// public double Width { get { return _width; } set { _width = value; } } private Brush _foreGround = Brushes.Black; ///
/// 字体颜色 /// public Brush ForeGround { get { return _foreGround; } set { _foreGround = value; } } private double _labelHeight = 15; ///
/// 左侧标题栏-单个标题高度 /// public double LabelHeight { get { return _labelHeight; } set { _labelHeight = value; } } private double _lineHeight = 0.2; ///
/// GridLine高度 /// public double LineHeight { get { return _lineHeight; } set { _lineHeight = value; } } private Brush _lineBrush = Brushes.Blue; ///
/// Bar填充颜色 /// public Brush LineBrush { get { return _lineBrush; } set { _lineBrush = value; } } List
_titles = new List
(); ///
/// 左侧标题列表 /// public List
Titles { get { return _titles; } set { _titles = value; } } } public class AxisYDataModel : DataModel { } #endregion public class DataModel { ///
/// 显示名称 /// public string Name { get; set; } ///
/// 值 /// public double Value { get; set; } }
View Code

3、控件引用

View Code

 GitHub下载地址:

 

如果需要不同的柱状图叠加:

 

Demo如下

UserControl:

View Code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace BarChartControlDemo{    ///     /// Interaction logic for BarChartControl.xaml    ///     public partial class BarChartControl : UserControl    {        public BarChartControl()        {            InitializeComponent();        }        public Brush BorderBrush        {            get { return (Brush)GetValue(BorderBrushProperty); }            set { SetValue(BorderBrushProperty, value); }        }        public static readonly DependencyProperty BorderBrushProperty = DependencyProperty.Register("BorderBrush",        typeof(Brush), typeof(BarChartControl),        new PropertyMetadata(Brushes.Black));        public Thickness BorderThickness        {            get { return (Thickness)GetValue(BorderThicknessProperty); }            set { SetValue(BorderThicknessProperty, value); }        }        public static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register("BorderThickness",        typeof(Thickness), typeof(BarChartControl),        new PropertyMetadata(new Thickness(1.0, 0.0, 1.0, 1.0)));        public AxisYModel AxisY        {            get { return (AxisYModel)GetValue(AxisYProperty); }            set { SetValue(AxisYProperty, value); }        }        public static readonly DependencyProperty AxisYProperty = DependencyProperty.Register("AxisY",        typeof(AxisYModel), typeof(BarChartControl),        new PropertyMetadata(new AxisYModel()));        public AxisXModel AxisX        {            get { return (AxisXModel)GetValue(AxisXProperty); }            set { SetValue(AxisXProperty, value); }        }        public static readonly DependencyProperty AxisXProperty = DependencyProperty.Register("AxisX",        typeof(AxisXModel), typeof(BarChartControl),        new PropertyMetadata(new AxisXModel()));        public double HeaderHeight        {            get { return (double)GetValue(HeaderHeightProperty); }            set { SetValue(HeaderHeightProperty, value); }        }        public static readonly DependencyProperty HeaderHeightProperty = DependencyProperty.Register("HeaderHeight",        typeof(double), typeof(BarChartControl), new PropertyMetadata(10.0));        public string Header        {            get { return (string)GetValue(HeaderProperty); }            set { SetValue(HeaderProperty, value); }        }        public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header",        typeof(string), typeof(BarChartControl), new PropertyMetadata());        private void BarChartControl_OnLoaded(object sender, RoutedEventArgs e)        {            MainBorder.BorderBrush = BorderBrush;            MainBorder.BorderThickness = BorderThickness;            HeaderGrid.Height = HeaderHeight;            MainBarContent.Height = MyScrollBoxFrom0To1.ActualHeight - 17;            LeftGrid.Width = AxisY.Width;            SetYTitlesContent();            SetXDatasContent();        }        private void SetXDatasContent()        {            var axisXModel = AxisX;            if (axisXModel.Datas.Count > 0)            {                int count = axisXModel.Datas[0].Datas.Count;                double barArea = axisXModel.BarWidth + axisXModel.MarginWidth * 2;                for (int i = 0; i < count + 1; i++)                {                    MainBarContent.ColumnDefinitions.Add(new ColumnDefinition()                    {                        Width = new GridLength(barArea)                    });                }                for (int index = 0; index < axisXModel.Datas[0].Datas.Count; index++)                {                    //主内容                    var stackPanel = new StackPanel();                    stackPanel.Orientation = Orientation.Vertical;                                        var tbl = new TextBlock();                    tbl.Height = 15;                    tbl.Text = string.Empty;                    if (axisXModel.Datas.Count<=1)                    {                        tbl.Text = axisXModel.Datas[0].Datas[index].ToString();                    }                    tbl.Foreground = axisXModel.ForeGround;                    tbl.HorizontalAlignment = HorizontalAlignment.Center;                    tbl.Margin=new Thickness(0,0,0,5);                    stackPanel.Children.Add(tbl);                    double allChartHeight = this.ActualHeight - BottomGrid.Height - HeaderHeight;                    foreach (var data in axisXModel.Datas)                    {                        var currentChartData = data.Datas[index];                        var radioButton = new RadioButton();                        radioButton.Template = (ControlTemplate)this.Resources["LightedBtnTemplate"];                        radioButton.Width = axisXModel.BarWidth;                        double maxValue = AxisY.Titles.Max(i => i.Value);                        radioButton.Height = (currentChartData.Value / maxValue) * allChartHeight;                        var linearBrush = new LinearGradientBrush()                        {                            StartPoint = new Point(1, 0),                            EndPoint = new Point(1, 1),                            GradientStops = new GradientStopCollection() {                                                 new GradientStop()                                                {                                                    Color = currentChartData.FillBrush, Offset = 0                                                }, new GradientStop()                                                {                                                    Color = currentChartData.FillEndBrush, Offset = 1                                                }                                            }                        };                        radioButton.Background = linearBrush;                        radioButton.HorizontalAlignment = HorizontalAlignment.Center;                        radioButton.Click += RadioButton_OnClick;                        stackPanel.Children.Add(radioButton);                    }                                        //底部                    var bottomTbl = new TextBlock();                    bottomTbl.Text = axisXModel.Datas[0].Datas[index].Name;                    bottomTbl.Foreground = axisXModel.ForeGround;                    bottomTbl.VerticalAlignment = VerticalAlignment.Center;                    bottomTbl.TextAlignment = TextAlignment.Center;                    bottomTbl.HorizontalAlignment = HorizontalAlignment.Center;                    double textBlockWidth = axisXModel.LabelWidth;                    bottomTbl.Width = axisXModel.LabelWidth;                    bottomTbl.Margin = new Thickness(0, 5, 0, 0);                    stackPanel.Children.Add(bottomTbl);                    Grid.SetColumn(stackPanel, index);                    stackPanel.Margin = new Thickness(0, 0, -textBlockWidth / 2, -17);                    stackPanel.VerticalAlignment = VerticalAlignment.Bottom;                    stackPanel.HorizontalAlignment = HorizontalAlignment.Right;                    MainBarContent.Children.Add(stackPanel);                    MainBarContent.Background = Brushes.Transparent;                }                                                                            double mainBarContentWidth = count * barArea;                if (mainBarContentWidth > MainGridFrom0To1Content.ActualWidth)                {                    BtnLeft.Visibility = Visibility.Visible;                    BtnRight.Visibility = Visibility.Visible;                }            }        }        public delegate void BarSelectionChangedEventArgs(object sender, RoutedEventArgs e);        public event BarSelectionChangedEventArgs BarSelectionChanged;        private void RadioButton_OnClick(object sender, RoutedEventArgs e)        {            var currentButton = sender as RadioButton;            foreach (var element in MainBarContent.Children)            {                var stackPanel = element as StackPanel;                foreach (var child in stackPanel.Children)                {                    if (child is RadioButton&& child !=currentButton)                    {                        (child as RadioButton).IsChecked = false;                    }                }            }            if (BarSelectionChanged!=null)            {                BarSelectionChanged(sender, e);            }        }        private void SetYTitlesContent()        {            var axisYModel = AxisY;            if (axisYModel.Titles.Count > 0)            {                int gridRows = axisYModel.Titles.Count - 1;                for (int i = 0; i < gridRows; i++)                {                    LeftGrid.RowDefinitions.Add(new RowDefinition());                    MainGridForRow1.RowDefinitions.Add(new RowDefinition());                }                int index = 0;                foreach (var title in axisYModel.Titles)                {                    var textblock = new TextBlock();                    textblock.Text = title.Name;                    textblock.Foreground = axisYModel.ForeGround;                    textblock.HorizontalAlignment = HorizontalAlignment.Right;                    textblock.Height = axisYModel.LabelHeight;                    if (index < gridRows)                    {                        textblock.VerticalAlignment = VerticalAlignment.Bottom;                        textblock.Margin = new Thickness(0, 0, 5, -axisYModel.LabelHeight / 2);//因为设置在行底部还不够,必须往下移                        Grid.SetRow(textblock, gridRows - index - 1);                    }                    else                    {                        textblock.VerticalAlignment = VerticalAlignment.Top;                        textblock.Margin = new Thickness(0, -axisYModel.LabelHeight / 2, 5, 0);//最后一个,设置在顶部                        Grid.SetRow(textblock, 0);                    }                    LeftGrid.Children.Add(textblock);                    var border = new Border();                    border.Height = axisYModel.LineHeight;                    border.BorderBrush = axisYModel.LineBrush;                    double thickness = Convert.ToDouble(axisYModel.LineHeight) / 2;                    border.BorderThickness = new Thickness(0, thickness, 0, thickness);                    if (index < gridRows)                    {                        border.VerticalAlignment = VerticalAlignment.Bottom;                        border.Margin = new Thickness(0, 0, 0, -thickness);//因为设置在行底部还不够,必须往下移                        Grid.SetRow(border, gridRows - index - 1);                    }                    else                    {                        border.VerticalAlignment = VerticalAlignment.Top;                        border.Margin = new Thickness(0, -thickness, 0, 0);//最后一个,设置在顶部                        Grid.SetRow(border, 0);                    }                    Grid.SetColumn(border, 0);                    Grid.SetColumnSpan(border, AxisX.Datas.Count + 1);                    MainGridForRow1.Children.Add(border);                    index++;                }            }        }        ///         /// 设置分行        ///         ///         ///         private void SetGridRowDefinitions(Grid leftGrid, int count)        {            for (int i = 0; i < count; i++)            {                leftGrid.RowDefinitions.Add(new RowDefinition());            }        }        ///         /// 向左滑动        ///         ///         ///         private void BtnLeft_OnClick(object sender, RoutedEventArgs e)        {            var startOffset = MyScrollBoxFrom0To1.HorizontalOffset;            if (startOffset <= _lastHorizontalOffset)            {                MyScrollBoxFrom0To1.HorizontalOffset = startOffset - 100;                _lastHorizontalOffset = startOffset - 100;            }            else if (startOffset > _lastHorizontalOffset)            {                BtnLeft.Opacity = 0.5;            }            BtnRight.Opacity = 1;        }        private double _lastHorizontalOffset = 0;        ///         /// 向右滑动        ///         ///         ///         private void BtnRight_OnClick(object sender, RoutedEventArgs e)        {            var startOffset = MyScrollBoxFrom0To1.HorizontalOffset;            if (startOffset >= _lastHorizontalOffset)            {                MyScrollBoxFrom0To1.HorizontalOffset = startOffset + 100;                _lastHorizontalOffset = startOffset + 100;            }            else if (startOffset < _lastHorizontalOffset)            {                BtnRight.Opacity = 0.5;            }            BtnLeft.Opacity = 1;        }    }    #region XDataModel    public class AxisXModel    {        private double _labelWidth = 20;        ///         /// 底部标签-单个宽度        ///         public double LabelWidth        {            get { return _labelWidth; }            set { _labelWidth = value; }        }        private double _marginWidth = 20;        ///         /// Bar间隔宽度        ///         public double MarginWidth        {            get { return _marginWidth; }            set { _marginWidth = value; }        }        private double _height = 20;        ///         /// 高度        ///         public double Height        {            get            {                return _height;            }            set { _height = value; }        }        private Brush _foreGround = Brushes.Black;        ///         /// 字体颜色        ///         public Brush ForeGround        {            get { return _foreGround; }            set { _foreGround = value; }        }        private double _barWidth = 30;        ///         /// Bar宽度        ///         public double BarWidth        {            get { return _barWidth; }            set { _barWidth = value; }        }        List
_datas = new List
(); ///
/// 数据集合 /// public List
Datas { get { return _datas; } set { _datas = value; } } } ///
/// 一组数据 /// public class AxisXData { public string Name { get; set; } List
_dataModels = new List
(); ///
/// 数据 /// public List
Datas { get { return _dataModels; } set { _dataModels = value; } } } public class AxisXDataModel : DataModel { private Color _fillBrush = Colors.Blue; ///
/// Bar填充颜色 /// public Color FillBrush { get { return _fillBrush; } set { _fillBrush = value; } } private Color _fillEndBrush = Colors.Blue; public Color FillEndBrush { get { return _fillEndBrush; } set { _fillEndBrush = value; } } } #endregion #region YDataModel public class AxisYModel { private double _width = 20; ///
/// 宽度 /// public double Width { get { return _width; } set { _width = value; } } private Brush _foreGround = Brushes.Black; ///
/// 字体颜色 /// public Brush ForeGround { get { return _foreGround; } set { _foreGround = value; } } private double _labelHeight = 15; ///
/// 左侧标题栏-单个标题高度 /// public double LabelHeight { get { return _labelHeight; } set { _labelHeight = value; } } private double _lineHeight = 0.2; ///
/// GridLine高度 /// public double LineHeight { get { return _lineHeight; } set { _lineHeight = value; } } private Brush _lineBrush = Brushes.Blue; ///
/// Bar填充颜色 /// public Brush LineBrush { get { return _lineBrush; } set { _lineBrush = value; } } List
_titles = new List
(); ///
/// 左侧标题列表 /// public List
Titles { get { return _titles; } set { _titles = value; } } } public class AxisYDataModel : DataModel { } #endregion public class DataModel { ///
/// 显示名称 /// public string Name { get; set; } ///
/// 值 /// public double Value { get; set; } }}
View Code

界面引用:

View Code

 

注:此案例需要下载DevExpress控件~

 

作者:
出处:
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。
你可能感兴趣的文章
更多API知识学习
查看>>
空值排序(oracle/sqlserver)
查看>>
[letcode] 832 Flipping an Image
查看>>
Mybatis - 入门
查看>>
Snmp协议应用-扫描局域网内打印机
查看>>
51CTO下载中心
查看>>
系统启动和内核管理
查看>>
U盘安装windows系统
查看>>
oracle 11g安装过程中提示
查看>>
实验三 贪心算法 多机调度问题
查看>>
postgresql查看慢查询
查看>>
如何实现两个JSP数据的传输
查看>>
WordPress广告管理插件 想赚钱来这里
查看>>
office宏分析
查看>>
记事本应用程序java源代码
查看>>
如何优化cocos2d程序的内存使用和程序大小
查看>>
struts 配置
查看>>
修改Windows Phone 7短信群发是彩信的问题
查看>>
高速控制DSP开发板SR-MK3-PRO
查看>>
IIS7+PHP
查看>>