WPF DevExpress ChartControl
前端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | <!--完整坐标图--> <dxc:ChartControl Grid.Row= "1" Grid.Column= "1" Name= "LbarChart" BorderThickness= "0" EnableAnimation= "True" Background= "#FF3D6DAF" > <!--鼠标选择后显示的面板--> <dxc:ChartControl.CrosshairOptions> <dxc:CrosshairOptions ShowArgumentLine= "True" GroupHeaderPattern= "{}时间: {A}" > <dxc:CrosshairOptions.CommonLabelPosition> <dxc:CrosshairFreePosition DockTarget= "{Binding ElementName=pane}" /> </dxc:CrosshairOptions.CommonLabelPosition> </dxc:CrosshairOptions> </dxc:ChartControl.CrosshairOptions> <!--坐标图--> <dxc:ChartControl.Diagram > <dxc:XYDiagram2D LabelsResolveOverlappingMinIndent= "2" x:Name= "Ldiagram" > <!--整个坐标面板--> <dxc:XYDiagram2D.DefaultPane> <dxc:Pane x:Name= "Lpane" DomainBrush= "#FF3D6DAF" Foreground= "White" /> </dxc:XYDiagram2D.DefaultPane> <!--Y轴设置--> <dxc:XYDiagram2D.AxisY> <dxc:AxisY2D GridLinesMinorVisible= "True" > <dxc:AxisY2D.Title> <dxc:AxisTitle Content= "温度湿度线性图" /> </dxc:AxisY2D.Title> </dxc:AxisY2D> </dxc:XYDiagram2D.AxisY> <!--X轴设置--> <dxc:XYDiagram2D.AxisX> <dxc:AxisX2D GridLinesVisible= "True" /> </dxc:XYDiagram2D.AxisX> <!--坐标图系列--> <dxc:XYDiagram2D.Series> <dxc:LineSeries2D x:Name= "LBarSideSerie" DisplayName= "温度" MarkerSize= "{Binding ElementName=slMarkerSize, Path=Value}" MarkerVisible= "{Binding ElementName=chbMarkers, Path=IsChecked}" AnimationAutoStartMode= "SetStartState" > <dxc:LineSeries2D.Label> <dxc:SeriesLabel ConnectorVisible= "False" ResolveOverlappingMode= "Default" dxc:MarkerSeries2D.Angle= "{Binding ElementName=slAngle, Path=Value}" Visible= "{Binding ElementName=chbVisible, Path=IsChecked}" /> </dxc:LineSeries2D.Label> <dxc:LineSeries2D.Points> </dxc:LineSeries2D.Points> </dxc:LineSeries2D> <dxc:LineSeries2D x:Name= "LBarSideSerie2" DisplayName= "湿度" MarkerSize= "{Binding ElementName=slMarkerSize, Path=Value}" MarkerVisible= "{Binding ElementName=chbMarkers, Path=IsChecked}" AnimationAutoStartMode= "SetStartState" > <dxc:LineSeries2D.Label> <dxc:SeriesLabel ConnectorVisible= "False" ResolveOverlappingMode= "Default" dxc:MarkerSeries2D.Angle= "{Binding ElementName=slAngle, Path=Value}" Visible= "{Binding ElementName=chbVisible, Path=IsChecked}" /> </dxc:LineSeries2D.Label> <dxc:LineSeries2D.Points> </dxc:LineSeries2D.Points> </dxc:LineSeries2D> <dxc:LineSeries2D x:Name= "LBarSideSerie3" DisplayName= "压强" MarkerSize= "{Binding ElementName=slMarkerSize, Path=Value}" MarkerVisible= "{Binding ElementName=chbMarkers, Path=IsChecked}" AnimationAutoStartMode= "SetStartState" > <dxc:LineSeries2D.Label> <dxc:SeriesLabel ConnectorVisible= "False" ResolveOverlappingMode= "Default" dxc:MarkerSeries2D.Angle= "{Binding ElementName=slAngle, Path=Value}" Visible= "{Binding ElementName=chbVisible, Path=IsChecked}" /> </dxc:LineSeries2D.Label> <dxc:LineSeries2D.Points> </dxc:LineSeries2D.Points> </dxc:LineSeries2D> </dxc:XYDiagram2D.Series> </dxc:XYDiagram2D> </dxc:ChartControl.Diagram> <!--图例--> <dxc:ChartControl.Legend> <dxc:Legend HorizontalPosition= "Right" Foreground= "White" Background= "{x:Null}" /> </dxc:ChartControl.Legend> </dxc:ChartControl> |
后台绑定值
/// <summary> /// 坐标绑值 /// </summary> /// <param name="TempData"></param> /// <param name="BarSideSerie"></param> /// <param name="diagram"></param> /// <param name="Name"></param> /// <param name="IsAddSecondaryY">是否添加第二坐标</param> public void SetBadingData(ParamVM TempData, LineSeries2D BarSideSerie, XYDiagram2D diagram, string Name, SolidColorBrush _brush, bool IsAddSecondaryY = true) { try { List<DevExpress.Xpf.Charts.SeriesPoint> lsBarPoint = new List<DevExpress.Xpf.Charts.SeriesPoint>(); //投入柱形图数据源 List<PPPTS> lstPPPTS = new List<PPPTS>(); #region 温度 List<DevChartData> lst = new List<DevChartData>(); lst = TempData.Lst.OrderByDescending(a => a.StartTime).ToList(); lsBarPoint.Clear(); List<DevChartData> lst2 = new List<DevChartData>(); foreach (var item in lst) { lst2.Add(item); if (lst2.Count > 100) break; } lst2 = lst2.OrderBy(a => a.StartTime).ToList(); foreach (var item in lst2) { lsBarPoint.Add(new DevExpress.Xpf.Charts.SeriesPoint() { Argument = DataConvert.GetValDateTime(item.StartTime).ToString("HH:mm"), Value = DataConvert.GetValDouble(item.ProductionLong) }); } BarSideSerie.Points.Clear(); BarSideSerie.Points.AddRange(lsBarPoint); BarSideSerie.Animate(); BarSideSerie.ArgumentScaleType = DevExpress.Xpf.Charts.ScaleType.Qualitative; BarSideSerie.LabelsVisibility = true;//显示标注标签 BarSideSerie.LabelsVisibility = false;//显示标注标签 BarSideSerie.Brush = _brush;//暂时不使用 if (IsAddSecondaryY) { #region 是否添加第二坐标 SecondaryAxisY2D ys = null; foreach (var item in diagram.SecondaryAxesY) { if (item.Title.Content.ToString() == Name) { ys = item; diagram.SecondaryAxesY.Remove(ys); break; } } SecondaryAxisY2D y1 = new SecondaryAxisY2D(); y1.Alignment = AxisAlignment.Near; y1.FontSize = 12; y1.Title = new AxisTitle() { Content = Name }; y1.Title.Foreground = _brush; y1.Title.FontSize = 12; y1.Title.Alignment = TitleAlignment.Far; //顶部对齐 y1.Range = new AxisRange() { MaxValue = DataConvert.GetValDouble(TempData.theMax) * (1.2), MinValue = DataConvert.GetValDouble(TempData.theMin) * (0.8) }; y1.Brush = _brush; y1.FontSize = 12; y1.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));//0000FF; y1.FontSize = 12; y1.OpacityMask = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));//0000FF; //AxisY.Visible = false; y1.Brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));//0000FF; y1.Label = new AxisLabel(); y1.Label.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));//0000FF; y1.Title.Visible = true; y1.Visible = false; diagram.SecondaryAxesY.Add(y1); XYDiagram2D.SetSeriesAxisY(BarSideSerie, y1); #endregion } else { AxisY2D AxisY = ((DevExpress.Xpf.Charts.XYDiagram2D)diagram).ActualAxisY; DevExpress.Xpf.Charts.AxisRange _Range = new DevExpress.Xpf.Charts.AxisRange() { MaxValue = DataConvert.GetValDouble(TempData.theMax) * (1.2), MinValue = DataConvert.GetValDouble(TempData.theMin) * (0.8) }; AxisY.Range = _Range; AxisY.Title = new AxisTitle() { Content = Name }; AxisY.Title.FontSize = 12; AxisY.Title.Alignment = TitleAlignment.Far; //顶部对齐 AxisY.Title.Foreground = _brush; AxisY.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));//0000FF; AxisY.FontSize = 12; AxisY.OpacityMask = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));//0000FF; AxisY.Brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));//0000FF; AxisY.Label = new AxisLabel(); AxisY.Label.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));//0000FF; AxisY.Title.Visible = false; AxisY.Visible = true; }; #endregion } catch (Exception) { throw; } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2020-01-13 VS2013 产品密钥 – 所有版本