DevExpress-ChartControl获取barWidth In Pixel

 坑:如果是SideBySideStackedBarSeriesView的话, 看看有 多少个 Group 需要 注意一下

private void chartControl1_CustomPaint(object sender, DevExpress.XtraCharts.CustomPaintEventArgs e) {
            var chart = ( ChartControl ) sender;
            var diagram = ( XYDiagram ) chart.Diagram;
            int barWidth = GetBarWidth(chart);

            int barHeight = 0;
            int barLocation = 0;

            var pt1 = diagram.DiagramToPoint(1, 1);
            var pt10 = diagram.DiagramToPoint(1, 0);
            var pt2 = diagram.DiagramToPoint(2, 2);
            var distance = pt2.Point.X - pt1.Point.X;

            this.barWidth.Text = (( SideBySideStackedBarSeriesView ) chart.Series [0].View).BarWidth.ToString();
            this.barWidth2.Text = barWidth.ToString();
            this.spacing.Text = distance.ToString(); ;

            int height = pt10.Point.Y - pt1.Point.Y;

            e.Graphics.DrawRectangle(new Pen(Color.Black), new Rectangle(
                new Point(pt1.Point.X - (barWidth / 2), pt1.Point.Y)
                , new Size((pt2.Point.X - pt1.Point.X + barWidth), height)));
        }

        public int GetXDistinceInPixel(XYDiagram diagram, string x1, int y1, string x2, int y2) {
            var pt1 = diagram.DiagramToPoint(1, 1);
            var pt2 = diagram.DiagramToPoint(2, 2);
            return pt2.Point.X - pt1.Point.X;
        }

        public int GetYDistinceInPixel(XYDiagram diagram, string x1, int y1, string x2, int y2) {
            var pt1 = diagram.DiagramToPoint(1, 1);
            var pt2 = diagram.DiagramToPoint(2, 2);
            return pt2.Point.Y - pt1.Point.Y;
        }

        public int GetBarWidth(ChartControl chart) {
            int barWidth = 0;
            if (chart.Series.Count > 0 && chart.Series [0].Points.Count > 1) {
                ControlCoordinates cc1 = (chart.Diagram as XYDiagram2D).DiagramToPoint(chart.Series ["Series 3"].Points [0].Argument, 0);
                ControlCoordinates cc2 = (chart.Diagram as XYDiagram2D).DiagramToPoint(chart.Series ["Series 3"].Points [1].Argument, 0);
                barWidth = Convert.ToInt32(
                    Math.Round((cc2.Point.X - cc1.Point.X) * (( SideBySideStackedBarSeriesView ) chart.Series [0].View).BarWidth, 0)
                        );
            }
            return barWidth;
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值