ZedGraph 横向的状柱状图 (Histogram Bar)

本文介绍了一种使用特定库绘制水平条形图的方法。通过设置图表属性和填充数据,展示了如何创建带有不同颜色梯度的条形图,并设置了X轴为序数类型,最后实现了条形的水平显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   

 private void OnRenderGraph(ZedGraphWeb zgw, Graphics g, MasterPane masterPane)
    {
        // Get the GraphPane so we can work with it
        GraphPane myPane = masterPane[0];

        // Set the title and axis labels
        myPane.Title.Text = "Horizontal Bar Graph";
        myPane.XAxis.Title.Text = "Performance Factor";
        myPane.YAxis.Title.Text = "Grouping";

        // Enter some random data values
        double[] y = { 100, 100, 75, 22, 98, 40, 10 };
        double[] y2 = { 90, 100, 95, 35, 80, 35, 35 };
        double[] y3 = { 80, 100, 65, 15, 54, 67, 18 };

        // Generate a bar with "Curve 1" in the legend
        BarItem myCurve = myPane.AddBar("Curve 1", y, null, Color.Red);
        // Fill the bar with a red-white-red gradient
        myCurve.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red, 90F);

        // Generate a bar with "Curve 2" in the legend
        myCurve = myPane.AddBar("Curve 2", y2, null, Color.Blue);
        // Fill the bar with a blue-white-blue gradient for a 3d look
        myCurve.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue, 90F);

        // Generate a bar with "Curve 3" in the legend
        myCurve = myPane.AddBar("Curve 3", y3, null, Color.Green);
        // Fill the bar with a Green-white-Green gradient for a 3d look
        myCurve.Bar.Fill = new Fill(Color.White, Color.Green, 90F);

        // Draw the X tics between the labels instead of at the labels
        myPane.YAxis.MajorTic.IsBetweenLabels = true;       

        // Set the XAxis to an ordinal type
        myPane.YAxis.Type = AxisType.Ordinal;
        myPane.XAxis.Scale.Max = 100;
        // draw the X axis zero line
        myPane.XAxis.MajorGrid.IsZeroLine = true;

        //This is the part that makes the bars horizontal
        myPane.BarSettings.Base = BarBase.Y;

        // Fill the axis background with a color gradient
        myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 45.0F);

        masterPane.AxisChange(g);
       
        //Create a label for each bar in the
        BarItem.CreateBarLabels(myPane, false, "0");

    }

C#简单变色龙游戏 /// /// 创建一副52张的新牌 /// /// public static System.Collections.ArrayList Creat() { System.Collections.ArrayList list = new System.Collections.ArrayList(); for (int i = 3; i <= 6; i++) { for (int j = 1; j <= 13; j++) { Poker p = new Poker(); switch (j) { case 1: p = new Poker((PokerStyle)i, "A", j, 11); break; case 2: p = new Poker((PokerStyle)i, j.ToString(), j, 10); break; case 11: p = new Poker((PokerStyle)i, "J", j, 11); break; case 12: p = new Poker((PokerStyle)i, "Q", j, 2); break; case 13: p = new Poker((PokerStyle)i, "K", j, 3); break; default: p = new Poker((PokerStyle)i, j.ToString(), j, j); break; } list.Add(p); } } return list; } /// /// 洗牌 /// /// /// public static System.Collections.ArrayList shuffle(System.Collections.ArrayList list)//洗牌 { System.Random r = new Random(); for (int i = 0; i <= 7; i++) { int rightOrRight = r.Next(1, 3); Poker[] leftPoker = new Poker[list.Count / 2]; Poker[] rightPoker = new Poker[list.Count % 2 == 0 ? list.Count / 2 : list.Count / 2 + 1]; list.CopyTo(0, leftPoker, 0, list.Count / 2); list.CopyTo(list.Count / 2, rightPoker, 0, list.Count % 2 == 0 ? list.Count / 2 : list.Count / 2 + 1); if (rightOrRight == 1)//左边插右边 { list.Clear(); for (int j = 0; j <= leftPoker.Length - 1; j++) { list.Add(rightPoker[j]); list.Add(leftPoker[j]); } if (leftPoker.Length != rightPoker.Length) { list.Add(rightPoker[rightPoker.Length - 1]); } } else { list.Clear(); for (int j = 0; j <= leftPoker.Length - 1; j++) { list.Add(leftPoker[j]); list.Add(rightPoker[j]); } if (leftPoker.Length != rightPoker.Length) { list.Add(rightPoker[rightPoker.Length - 1]); } } } return list; }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值