zoukankan      html  css  js  c++  java
  • 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" );
                    }
                }
            }

  • 相关阅读:
    CentOS7 1 安装 ansible
    CentOS7 prometheus +node_exporter+Grafana 配置篇(原创)
    CentOS7 prometheus +node_exporter+Grafana 安装篇
    Oracle 查询重复记录 只保留一条 (转载)
    MySQL 查询重复数据(转载)
    Mongodb 查询重复数据(转载)
    Python报错:pymongo.errors.CursorNotFound: Cursor not found
    百万级高并发MongoDB集群性能数十倍提升优化实践(上篇)
    OPPO百万级高并发mongodb集群性能数十倍提升优化实践(下篇) 转载
    Oracle 常见等待事件及处理方法
  • 原文地址:https://www.cnblogs.com/grj001/p/12225294.html
Copyright © 2011-2022 走看看