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

   

 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");

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要使用ZedGraph绘制曲线图,你需要做以下几个步骤: 1. 引用ZedGraph.dll程序集 在你的项目中添加对ZedGraph.dll程序集的引用。你可以在ZedGraph官网上下载最新版本的程序集。 2. 创建ZedGraph控件 在你的窗体或用户控件上创建一个ZedGraph控件。你可以在Visual Studio中从工具箱中拖动和放置ZedGraph控件,也可以在代码中创建它。 ```csharp using ZedGraph; // 创建一个名为"graphControl"的ZedGraph控件 ZedGraphControl graphControl = new ZedGraphControl(); this.Controls.Add(graphControl); ``` 3. 创建曲线对象 使用ZedGraph库中的LineItem类创建曲线对象,然后将数据点添加到曲线中。 ```csharp // 创建曲线对象 LineItem curve = graphControl.GraphPane.AddCurve("My Curve", new PointPairList(), Color.Blue, SymbolType.None); // 添加数据点 PointPairList pointList = new PointPairList(); pointList.Add(x1, y1); pointList.Add(x2, y2); // ... curve.Points = pointList; ``` 4. 配置图表属性 设置图表的标题、坐标轴标签、背景颜色等属性。 ```csharp // 设置图表属性 GraphPane myPane = graphControl.GraphPane; myPane.Title.Text = "My Graph"; myPane.XAxis.Title.Text = "X Axis"; myPane.YAxis.Title.Text = "Y Axis"; myPane.Fill = new Fill(Color.White, Color.LightGray, 45.0f); ``` 5. 刷新控件 最后,调用控件的Refresh方法来刷新曲线图。 ```csharp graphControl.AxisChange(); graphControl.Invalidate(); graphControl.Refresh(); ``` 完整的代码示例: ```csharp using ZedGraph; // 创建一个名为"graphControl"的ZedGraph控件 ZedGraphControl graphControl = new ZedGraphControl(); this.Controls.Add(graphControl); // 创建曲线对象 LineItem curve = graphControl.GraphPane.AddCurve("My Curve", new PointPairList(), Color.Blue, SymbolType.None); // 添加数据点 PointPairList pointList = new PointPairList(); pointList.Add(x1, y1); pointList.Add(x2, y2); // ... curve.Points = pointList; // 设置图表属性 GraphPane myPane = graphControl.GraphPane; myPane.Title.Text = "My Graph"; myPane.XAxis.Title.Text = "X Axis"; myPane.YAxis.Title.Text = "Y Axis"; myPane.Fill = new Fill(Color.White, Color.LightGray, 45.0f); // 刷新控件 graphControl.AxisChange(); graphControl.Invalidate(); graphControl.Refresh(); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值