• DevExpress ChartControl 第二Y轴刻度, 满足条件 Point 变色


    This example demonstrates how secondary axes can be added to a chart at runtime.

    C#

    VB

     
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using DevExpress.XtraCharts;
    // ... 
    
    private void Form1_Load(object sender, EventArgs e) {
        // Create a new chart. 
        ChartControl chartControl1 = new ChartControl();
    
        // Create two series. 
        Series series1 = new Series("Series 1", ViewType.Bar);
        Series series2 = new Series("Series 2", ViewType.Line);
    
        // Add points to them, with their arguments different. 
        series1.Points.Add(new SeriesPoint("A", 10));
        series1.Points.Add(new SeriesPoint("B", 12));
        series1.Points.Add(new SeriesPoint("C", 17));
        series1.Points.Add(new SeriesPoint("D", 14));
        series2.Points.Add(new SeriesPoint("I", 1500));
        series2.Points.Add(new SeriesPoint("II", 1800));
        series2.Points.Add(new SeriesPoint("III", 2500));
        series2.Points.Add(new SeriesPoint("IV", 3300));
    
        // Add both series to the chart. 
        chartControl1.Series.AddRange(new Series[] { series1, series2 });
    
        // Hide the legend (optional). 
        chartControl1.Legend.Visible = false;
    
        // Create two secondary axes, and add them to the chart's Diagram. 
        SecondaryAxisX myAxisX = new SecondaryAxisX("my X-Axis");
        SecondaryAxisY myAxisY = new SecondaryAxisY("my Y-Axis");
    
        ((XYDiagram)chartControl1.Diagram).SecondaryAxesX.Add(myAxisX);
        ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add(myAxisY);
    
        // Assign the series2 to the created axes. 
        ((LineSeriesView)series2.View).AxisX = myAxisX;
        ((LineSeriesView)series2.View).AxisY = myAxisY;
    
        // Customize the appearance of the secondary axes (optional). 
        myAxisX.Title.Text = "A Secondary X-Axis";
        myAxisX.Title.Visible = true;
        myAxisX.Title.TextColor = Color.Red;
        myAxisX.Label.TextColor = Color.Red;
        myAxisX.Color = Color.Red;
    
        myAxisY.Title.Text = "A Secondary Y-Axis";
        myAxisY.Title.Visible = true;
        myAxisY.Title.TextColor = Color.Blue;
        myAxisY.Label.TextColor = Color.Blue;
        myAxisY.Color = Color.Blue;
    
        // Add the chart to the form. 
        chartControl1.Dock = DockStyle.Fill;
        this.Controls.Add(chartControl1);
    }

    左侧, 右侧坐标轴

        ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Clear();//清空之前的右侧坐标, 可以有多个坐标轴
     ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add( myAxisY );
    ((StackedLineSeriesView)workTimeSeries.View).AxisY = ((XYDiagram)chartControl1.Diagram).SecondaryAxesY[0];//右侧坐标轴

    鼠标靠近时, 显示 弹出框

     private void CustomDrawCrosshairEventArgs ( CustomDrawCrosshairEventArgs e ) {
             if (e.CrosshairElementGroups.Count == 0) { return; }
             foreach (CrosshairElement element in e.CrosshairElementGroups[0].CrosshairElements) {
                 SeriesPoint currentPoint = element.SeriesPoint;
                 if (currentPoint.Tag.GetType() == typeof( DataRowView )) {
                     DataRowView rowView = (DataRowView)currentPoint.Tag;
                     string s = rowView[3].ToString();
                     element.LabelElement.Text = s;
                 }
             }

    满足条件, 修改颜色

    private void chartControl1_CustomDrawSeriesPoint ( object sender, DevExpress.XtraCharts.CustomDrawSeriesPointEventArgs e ) {
                ChartHitInfo info = chartControl1.CalcHitInfo( this.chartControl1.PointToClient( MousePosition ) );

                //如果容量为 0 那么为绿色
                //if (e.SeriesPoint.Argument == "A") {
                //    ((PointDrawOptions)e.SeriesDrawOptions).Color = Color.Blue;
                //} else if (e.SeriesPoint.Argument == "B") {
                //    ((PointDrawOptions)e.SeriesDrawOptions).Color = Color.Red;
                //}
                if (e.Series.Name == "数量") {
                    ChartControl chartControl = sender as ChartControl;
                    List<SeriesPoint> points = chartControl.Series["容量"].Points.Select( x => x as SeriesPoint ).ToList();
                    string argumentName = e.SeriesPoint.Argument;   //名称
                    double hangerCapacity = points.Where( x => x.Argument == argumentName ).First().Values[0];

                    if (hangerCapacity == 0) {
                        //e.SeriesDrawOptions.Color = Color.Black;
                        //e.SeriesPoint.Annotations.AddTextAnnotation( "TextAnnotation" );
                    }
                }
            }

  • 相关阅读:
    测试平台系列(38) 接入github第三方登录(上)
    测试平台系列(37) 运用装饰器给用例加上执行日志
    测试平台系列(36) 使用全局变量
    测试平台系列(35) 编写全局变量管理页面
    OCP 063中文考试题库(cuug内部资料)第16题
    OCP 063中文考试题库(cuug内部资料)第15题
    D. Strange Housing 题解(思维+染色)
    B. Strange Definition 题解(质因子分解+思维)
    F. Euclid's nightmare 题解(MST+思维)
    D. Fragmentation merging 题解(思维)
  • 原文地址:https://www.cnblogs.com/grj001/p/12225294.html
Copyright © 2020-2023  润新知