WPF DevExpress ChartControl使用之XYDiagram

WPF使用Dev和WinForm有许多不同,相对而言,WPF要更简单和炫酷一点,我只做了一点基本的功能,没有仔细的研究,这里只介绍一下WPF Dev ChartControl绘制XYDiagram的基础。

XYDiagramControl.xaml页面

<UserControl
         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:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
         xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
         x:Class="WpfControl.XYDiagramControl"
         mc:Ignorable="d">
    <Grid>
        <dxc:ChartControl HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top">
            <dxc:XYDiagram2D  LabelsResolveOverlappingMinIndent="2" x:Name="diagram1" EnableAxisXNavigation="True">
                <dxc:XYDiagram2D.DefaultPane>
                    <dxc:Pane Name="pane"/>
                </dxc:XYDiagram2D.DefaultPane>
                <dxc:XYDiagram2D.AxisY>
                    <dxc:AxisY2D GridLinesMinorVisible="False">
                    </dxc:AxisY2D>
                </dxc:XYDiagram2D.AxisY>
                <dxc:XYDiagram2D.SecondaryAxesY>
                </dxc:XYDiagram2D.SecondaryAxesY>
                <dxc:XYDiagram2D.AxisX>
                    <dxc:AxisX2D GridLinesVisible="False"/>
                </dxc:XYDiagram2D.AxisX>
                <dxc:LineSeries2D MarkerVisible="True" LabelsVisibility="True" ArgumentDataMember="Key" ValueDataMember="Value" x:Name="series1">
                    <dxc:LineSeries2D.LineStyle>
                         <dxc:LineStyle Thickness="1" />
                    </dxc:LineSeries2D.LineStyle>
                </dxc:LineSeries2D>
            </dxc:XYDiagram2D>
            <dxc:ChartControl.Legend>
                <dxc:Legend HorizontalPosition="Right"/>
            </dxc:ChartControl.Legend>
            <dxc:ChartControl.ToolTipController>
                <dxc:ChartToolTipController AutoPopDelay="0" InitialDelay="0"/>
            </dxc:ChartControl.ToolTipController>
        </dxc:ChartControl>
    </Grid>
</UserControl>

XYDiagramControl.cs页面

using System.Collections.Generic;
using System.Windows.Controls;
using DevExpress.Xpf.Charts;
using Dugufeixue.Common;
namespace WpfControl
{
    /// <summary>
    /// UserControl2.xaml 的交互逻辑
    /// </summary>
    public partial class XYDiagramControl : UserControl
    {
        double maxValue = 0;
        private char divider = ‘_‘;
        public XYDiagramControl(List<DataEntity> decs, bool isLine, bool isShowLabel, bool isSameY)
        {
            InitializeComponent();
            int index = 0;
            foreach (DataEntity de in decs)
            {
                Series series = null;
                if (!isSameY)
                {
                    //设置Y轴的第二坐标
                    SecondaryAxisY2D SecondaryAxisY = new SecondaryAxisY2D();
                    diagram1.SecondaryAxesY.Add(SecondaryAxisY);
                    //设置第二坐标的标题
                    AxisTitle title = new AxisTitle();
                    title.Content = de.Ytitle;
                    SecondaryAxisY.Title = title;
                    if (isLine)
                    {
                        //新建一个折线图
                        series = new LineSeries2D();
                        //设置series与第二坐标轴关联
                        XYDiagram2D.SetSeriesAxisY((LineSeries2D)series, SecondaryAxisY);
                    }
                    else
                    {
                        //新建一个柱状图
                        series = new BarSideBySideSeries2D();
                        //设置柱状图的Label
                        SeriesLabel label = new SeriesLabel();
                        label.Indent = 20;
                        series.Label = label;
                        if (isShowLabel)
                        {
                            BarSideBySideSeries2D.SetLabelPosition(series.Label, Bar2DLabelPosition.Outside);
                        }
                        XYDiagram2D.SetSeriesAxisY((BarSideBySideSeries2D)series, SecondaryAxisY);
                    }
                }
                else
                {
                    if (isLine)
                    {
                        series = new LineSeries2D();
                    }
                    else
                    {
                        series = new BarSideBySideSeries2D();
                        SeriesLabel label = new SeriesLabel();
                        label.Indent = 20;
                        series.Label = label;
                        if (isShowLabel)
                        {
                            BarSideBySideSeries2D.SetLabelPosition(series.Label, Bar2DLabelPosition.Outside);
                        }
                    }
                }
                series.Name = "series" + index;
                series.DisplayName = de.Displayname;
                //设置series的数据源
                series.DataSource = de.Dic;
                series.LabelsVisibility = isShowLabel;
                series.ArgumentDataMember = "Key";
                series.ValueDataMember = "Value";
                //向XYDiagram中添加series
                diagram1.Series.Add(series);
                index++;
            }
        }
    }
}
时间: 2024-11-03 21:34:47

WPF DevExpress ChartControl使用之XYDiagram的相关文章

DevExpress ChartControl大数据加载时有哪些性能优化方法

DevExpress ChartControl加载大数据量数据时的性能优化方法有哪些? 关于图表优化,可从以下几个方面解决: 1.关闭不需要的可视化的元素(如LineMarkers, Labels等): Series.View.LineMarkerOptions.Visible =false. 2. 关闭图表的滚动与缩放功能,手动调整范围,这样将大大减少所需计算的个数. 3. 将 ChartControl.RefreshDataOnRepaint属性设为false 4. 将 ChartContr

[Irving] Wpf DevexPress GridControl 获取选中行

WPF前台绑定事件代码: <RelayAction TargetControl="{Binding ElementName=GCInstoragePart}" MethodName="GridClick" MethodParameter="{XParamBinding me}" TriggerEvent="Click" /> 后台事件代码: public void GridClick(RelayAction r,

[DevExpress]ChartControl之时间轴示例

关键代码: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; namespace DevExpressChart { public partial class winDateTime : Form { public winDateTime() { InitializeComponent(); } private void winDateTime_Load(object

[DevExpress]ChartControl之柱状图演示

关键代码: using System; using System.Data; using System.Windows.Forms; using CSharpUtilHelpV2; using DevExpress.XtraCharts; namespace DevExpressChart { public partial class winProduct : Form { public winProduct() { InitializeComponent(); } static readonl

[DevExpress]ChartControl之SeriesTemplate演示

关键代码: using System; using System.Data; using System.Windows.Forms; using CSharpUtilHelpV2; using DevExpress.XtraCharts; namespace DevExpressChart { public partial class winGsp : Form { public winGsp() { InitializeComponent(); } static readonly string

初识Devexpress ChartControl 之 动态添加stepline及TextAnnotation

最近在用devexpress 第三方软件做项目. devexpress 的控件使用简单.功能强大.类型丰富.界面优美.扩展性强.今天主要是动态生成了一条StepLine.生成后的效果(能力不强,所以做的比较简单.): 首先,建立一个form(普通的或ribbonform均可),然后拖拽一个chartControl到form中.右键run warzid.然后将预设的线条删除(因为我们要动态添加). 然后查看form代码.在构造函数中添加方法调用InitCharControl(); 然后新建Init

WPF DevExpress 设置雷达图Radar样式

  DevExpress中定义的ChartControl很不错,很多项目直接使用这种控件. 本节讲述雷达图的样式设置 <Grid> <Grid.Resources> <DataTemplate x:Key="LabelItemDataTemplate" DataType="dxc:SeriesLabelItem"> <Border CornerRadius="8" Padding="8,1&qu

[DevExpress]ChartControl之滚动条示例

关键代码: /// <summary> /// 设置ChartControl滚动条[默认X,Y轴都出现] /// </summary> /// <param name="chart">ChartControl</param> /// <param name="backColor">滚动条背景颜色</param> /// <param name="barColor">

[DevExpress]ChartControl之创建Strip示例

关键代码: /// <summary> /// 创建Strip /// </summary> /// <param name="chart">ChartControl</param> /// <param name="strip">Strip</param> /// <param name="stripLable">Strip文字</param> //