zoukankan      html  css  js  c++  java
  • chartContrl 折线图添加报警线和一些其他设置 放大缩小折线图等

    //设置鼠标划过折线点时不显示图例 
    chartControl1.CrosshairEnabled = DefaultBoolean.False;
    
    async void SetDataDeepChart(List<ChartData> list)
            {
                try
                {
                    #region 按采集时间分组用于创建折线
                    //按测点名深度降序排列,第一条为Y轴最大值
                    //var orderList = list.OrderByDescending(o => o.Name.Split('-')[1]).ToList();
                    string name = list[0].Name;
                    string chartName = name.Length == 4 ? name.Substring(0, 2) : name.Substring(0, 3);
                    var newList = from fx in list
                                  where !string.IsNullOrEmpty(fx.Name)
                                  group fx by fx.Time.Date
                        into b
                                  select new
                                  {
                                      b.Key,
                                      Data = b
                                  };
    
                    #endregion
    
                    #region 添加折线图
    
                    foreach (var item in newList.OrderBy(o=>o.Key))
                    {
                        Series series = new Series
                        {
                            Name = chartName + @"-" + item.Key.ToString("yyyy.MM.dd"),
                            ValueScaleType = ScaleType.Numerical,
                            ArgumentScaleType = ScaleType.Numerical
                            
                        };
                        LineSeriesView lineSeriesView1 = new LineSeriesView
                        {
                            MarkerVisibility = DefaultBoolean.True
                        };
                        series.View = lineSeriesView1; //new LineSeriesView();
    
                        //设置鼠标悬停后提示框显示格式 {S}-名称 {A}-X轴值 {V}-Y轴值
                        series.CrosshairLabelPattern = "{S}:{A}:{V}";
                        
    
                        Series series1 = new Series
                        {
                            Name = chartName + @"-" + item.Key.ToString("yyyy.MM.dd"),
                            ValueScaleType = ScaleType.Numerical,
                            ArgumentScaleType = ScaleType.Numerical
                        };
    
                        LineSeriesView lineSeriesView2 = new LineSeriesView
                        {
                            MarkerVisibility = DefaultBoolean.True
                        };
                        
                        series1.View = lineSeriesView2; // new LineSeriesView();
                        //设置鼠标悬停后提示框显示格式 {S}-名称 {A}-X轴值 {V}-Y轴值
                        series1.CrosshairLabelPattern = "{S}:{A}:{V}";
    
                        var newDtos = list.Where(o => o.Time.Date == item.Key).ToList();
                       
                        foreach (var dto in newDtos.OrderBy(o=>o.Name))
                        {
                            //时间位移
                            series.Points.Add(new SeriesPoint(_controls.FirstOrDefault(o => o.Name == dto.Name)?.Depth,dto.ChangeSum));
                            //series.Points.Add(new SeriesPoint(dto.ChangeSum, _controls.FirstOrDefault(o=>o.Name==dto.Name)?.Depth));
    
                            //时间变化速率
                            //series1.Points.Add(new SeriesPoint(dto.ChangeV, _controls.FirstOrDefault(o => o.Name == dto.Name)?.Depth));
                            series1.Points.Add(new SeriesPoint(_controls.FirstOrDefault(o => o.Name == dto.Name)?.Depth, dto.ChangeV));
                        }
    
                        chartControl1.Series.Add(series);
                        chartControl2.Series.Add(series1);
                    }
    
                    #endregion
    
                    #region 根据类型和等级获取控制值,累积变化量,变化速率
    
                    ControlGetAllDto getAllDto = new ControlGetAllDto
                    {
                        ProjectKey = _project.ProjectID.ToString()
                    };
                    //List<ControlDto> dtos = await controlService.GetControlAll(getAllDto);
                    //ControlDto firstDto = dtos.FirstOrDefault(o => o.TypeName == _typeName && o.Level == _level);
                    //if (firstDto == null)
                    //    return;
    
                    #endregion
    
                    #region 添加报警值和控制值的警报线
    
                    var xyDiagram1 = (XYDiagram)chartControl1.Diagram;
                    //设置鼠标滚轮时折线图随着发生变大或缩小
                    xyDiagram1.EnableAxisXScrolling = true;
                    xyDiagram1.EnableAxisXZooming = true;
      //设置X轴显示年月日时分秒
    xyDiagram1.AxisX.DateTimeScaleOptions.MeasureUnit= DateTimeMeasureUnit.Second;
    xyDiagram1.AxisX.Label.TextPattern
    = "{A:yyyy-MM-dd HH:mm:ss}";
     
                    xyDiagram1.AxisX.MinorCount = 1;//刻度间隔个数为1
                    xyDiagram1.AxisX.NumericScaleOptions.AutoGrid = false;
                    xyDiagram1.AxisX.NumericScaleOptions.GridSpacing = 1D;//间隔为1
                    xyDiagram1.AxisX.VisibleInPanesSerializable = "-1";
                    xyDiagram1.AxisX.WholeRange.Auto = false;
                    xyDiagram1.AxisX.WholeRange.AutoSideMargins = false;
                    //string maxValue = list[0].Name.Split('-')[1];
                    //if (_project.Name == "3#院办公大楼")
                    //{
                    //    xyDiagram1.AxisX.WholeRange.MaxValueSerializable = "14";
                    //}
                    //xyDiagram1.AxisX.WholeRange.MinValueSerializable = "0";
                    xyDiagram1.AxisX.WholeRange.SideMarginsValue = 0D;//边界值,最大值=最大值+边界值
                    xyDiagram1.AxisX.Reverse = true;//Y轴坐标值反转显示,即最上面是0,越往下值越大
    
                    xyDiagram1.Rotated = true;//X轴和Y轴互换即竖向画折线
                    //ConstantLine constantLine1 = new ConstantLine
                    //{
                    //    AxisValueSerializable =_controls.FirstOrDefault(o=>o.Name==name).ChangeSum.ToString(),// firstDto.ChangeSum.ToString(),
                    //    Color = Color.Yellow,
                    //    Name = "Constant Line 1",
                    //    ShowInLegend = false
                    //};
    
                    //constantLine1.Title.Text = _typeName = @"报警值(" + _controls.FirstOrDefault(o => o.Name == name).ChangeSum + @")";
                    //constantLine1.Title.Alignment = ConstantLineTitleAlignment.Far;
                    //constantLine1.Title.TextColor = Color.Red;
                    ConstantLine constantLine2 = new ConstantLine
                    {
                        AxisValueSerializable = _controls.FirstOrDefault(o => o.Name == name).Value.ToString(),//firstDto.Value.ToString(),
                        Color = Color.Red,
                        Name = "Constant Line 2",
                        ShowInLegend = false
                    };
                    // firstDto.Value
                    constantLine2.Title.Text = _typeName = @"控制值(" + _controls.FirstOrDefault(o => o.Name == name).Value + @"";
                    constantLine2.Title.Alignment = ConstantLineTitleAlignment.Far;
                    constantLine2.Title.TextColor = Color.Red;
                    xyDiagram1.AxisX.Title.Text = @"深度(m)";
                    xyDiagram1.AxisX.Title.Visibility = DefaultBoolean.True;
                    xyDiagram1.AxisY.Title.Text = @"位移(mm)";
                    xyDiagram1.AxisY.Title.Visibility = DefaultBoolean.True;
                    xyDiagram1.AxisY.ConstantLines.AddRange(new[]
                    {
                         constantLine2
                    });
    
                    #endregion
    
                    #region 添加变化速率的警报线
    
                    var xyDiagram2 = (XYDiagram)chartControl2.Diagram;
    
                    xyDiagram2.AxisX.MinorCount = 1;//刻度间隔个数为1
                    xyDiagram2.AxisX.NumericScaleOptions.AutoGrid = false;
                    xyDiagram2.AxisX.NumericScaleOptions.GridSpacing = 1D;//间隔为1
                    xyDiagram2.AxisX.VisibleInPanesSerializable = "-1";
                    xyDiagram2.AxisX.WholeRange.Auto = false;
                    xyDiagram2.AxisX.WholeRange.AutoSideMargins = false;
                    //if (_project.Name == "3#院办公大楼")
                    //{
                    //    xyDiagram2.AxisX.WholeRange.MaxValueSerializable = "14";
                    //}
                    //xyDiagram2.AxisX.WholeRange.MinValueSerializable = "0";
                    xyDiagram2.AxisX.WholeRange.SideMarginsValue = 0D;//边界值,最大值=最大值+边界值
                    xyDiagram2.AxisX.Reverse = true;//Y轴坐标值反转显示,即最上面是0,越往下值越大
                    xyDiagram2.Rotated = true;//X轴和Y轴互换即竖向画折线
    
                    xyDiagram2.AxisX.Title.Text = @"深度(m)";
                    xyDiagram2.AxisX.Title.Visibility = DefaultBoolean.True;
                    xyDiagram2.AxisY.Title.Text = @"变化率(mm/d)";
                    xyDiagram2.AxisY.Title.Visibility = DefaultBoolean.True;
                    ConstantLine constantLine3 = new ConstantLine
                    {
                        AxisValueSerializable = _controls.FirstOrDefault(o => o.Name == name).ChangeV.ToString(),//firstDto.ChangeV.ToString(),
                        Color = Color.Red,
                        Name = "Constant Line 3",
                        ShowInLegend = false
                    };
    
                    constantLine3.Title.Text = @"变化速率(" + _controls.FirstOrDefault(o => o.Name == name).ChangeV + @"";
                    constantLine3.Title.Alignment = ConstantLineTitleAlignment.Far;
                    constantLine3.Title.TextColor = Color.Red;
    
                    xyDiagram2.AxisY.ConstantLines.AddRange(new[]
                    {
                        constantLine3
                    });
    
                    #endregion
    
                }
                catch (Exception ex)
                {
                    FileLogUtility.Error(ex);
                }
            }
  • 相关阅读:
    在虚拟机VM中安装的Ubuntu上安装和配置Hadoop
    初识Hadoop
    Hold住:坚持的智慧
    《人生若只如初见》读后感
    EAS部署:linux 下安装EAS后启动不了服务
    修改Tomcat默认端口
    IntelliJ IDEA工具使用总结
    Mac OSX 包管理工具
    Mac 下安装、卸载Java 7
    MySQL快速命令
  • 原文地址:https://www.cnblogs.com/ljy0905/p/6898695.html
Copyright © 2011-2022 走看看