ZedGraph显示柱状图

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZedGraph;

namespace ZedGraphDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ShowChart2();
        }

        private void ShowChart1()
        {
            zedGraphControl1.GraphPane.CurveList.Clear();
            zedGraphControl1.GraphPane.GraphObjList.Clear();
            GraphPane myPane = zedGraphControl1.GraphPane;
            myPane.Title.Text = "消费者学历统计"; //设计图表的标题 
            myPane.XAxis.Title.Text = "学历类型";//X轴标题 
            myPane.YAxis.Title.Text = "人数";//Y轴标题  
            PointPairList PPLa = new PointPairList();
            PointPairList PPLb = new PointPairList();
            PointPairList PPLc = new PointPairList();
            PointPairList PPLd = new PointPairList();
            for (int i = 1; i < 5; i++)
            {
                PPLa.Add(i, i + 3);
                PPLb.Add(i, i + 4);
                PPLc.Add(i, i + 5);
                PPLd.Add(i, i + 6);

            }
            BarItem myBara = myPane.AddBar("A", PPLa, Color.Red);
            BarItem myBarb = myPane.AddBar("B", PPLb, Color.Blue);
            BarItem myBarc = myPane.AddBar("C", PPLc, Color.Gray);
            BarItem myBard = myPane.AddBar("D", PPLd, Color.Black);
            zedGraphControl1.AxisChange();
            zedGraphControl1.Refresh();
        }

        private void ShowChart2()
        {
            zedGraphControl1.GraphPane.CurveList.Clear();
            zedGraphControl1.GraphPane.GraphObjList.Clear();
            GraphPane myPane = zedGraphControl1.GraphPane;
            myPane.Title.Text = "消费者学历统计"; //设计图表的标题 
            myPane.XAxis.Title.Text = "学历类型";//X轴标题 
            myPane.YAxis.Title.Text = "人数";//Y轴标题  
            PointPairList PPLa = new PointPairList();
            PointPairList PPLb = new PointPairList();
            PointPairList PPLc = new PointPairList();
            PointPairList PPLd = new PointPairList();
            for (int i = 1; i <= 5; i++)
            {
                PPLa.Add(i, i + 3);
                PPLb.Add(i, i + 4);
                PPLc.Add(i, i + 5);
                PPLd.Add(i, i + 6);

            }
            BarItem myBara = myPane.AddBar("A", PPLa, Color.Red);
            BarItem myBarb = myPane.AddBar("B", PPLb, Color.Blue);
            BarItem myBarc = myPane.AddBar("C", PPLc, Color.Gray);
            BarItem myBard = myPane.AddBar("D", PPLd, Color.Black);

            string[] labels = { "产品1", "产品2", "产品3", "产品4", "产品5" };
            myPane.XAxis.Scale.TextLabels = labels;
            myPane.XAxis.Type = AxisType.Text;
            //图区以外的颜色 
            myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f);
            //背景颜色 
            myPane.Chart.Fill = new Fill(Color.Red, Color.LightGoldenrodYellow, 45.0f);

            zedGraphControl1.AxisChange();
            zedGraphControl1.Refresh();
        }
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
软件介绍ZedGraphV515是C#编写的.NET类库,提供了用户控件和web控件。它可以创建2D的线性图、条形图和饼图。 它功能完整且有详细的功能自定义。 基于LGPL协议开源,.NET 2.0 C#源代码)它的思路清淅,所以非常容易就上手.几个注意点: 图片的保存路径设置:RenderedImagePath属性中设置,程序对该文件夹应该是有写和修改权限的 图片的输出格式:OutputFormat属性中设置,Png的推荐,比较清晰。 Chart ChartBorder 图表区域的边框设置 ChartFill 图表区域的背景填充 Legend 图表的注释标签显示设置项目,一组数据对应一种颜色的注释 IsHStack 当有多个显示项的时候设置Y轴数据是叠加的还是分开的 Xaxis 图表区域的X轴相关信息设置 AxisColor 坐标轴颜色 Cross 坐标的原点,可以设置坐标的偏移程度 CrossAuto 原点自动设置:True的话Cross的设置就无效了。 FontSpec X轴标题字体相关信息 Angle X轴标题字体显示时候的角度,0为水平 90为垂直 Fill X轴标题字体填充信息 ColorOpacity 透明度 IsScaled 设置X轴标题字体显示大小是否根据图的比例放大缩小 RangeMax 填充时候的最大倾斜度(有过渡色,没试过) RangeMin 填充时候的最小倾斜度(有过渡色,没试过) StringAlignment X轴标题字体排列(不清楚,没试过) IsOmitMag 是否显示指数幂(10次方,没试过,似乎与IsUseTenPower有关系) IsPreventLabelOverlap 坐标值显示是否允许重叠,如果False的话,控件会根据坐标值长度自动消除部分坐标值的显示状态 IsShowTitle X轴标题是否显示 IsTicsBetweenLabels 两个坐标值之间是否自动显示分隔标志 IsUseTenPower 是否使用10次幂指数 IsVisible 是否显示X轴source下为ZedGraphV515控件的源码
C知道:C#中的ZedGraph是一个强大的图表绘制库,它提供了丰富的功能来创建各种类型的图表,包括折线图、柱状图、饼图等。使用ZedGraph可以轻松地在C#应用程序中添加图表功能。 要使用ZedGraph,首先需要将ZedGraph库添加到你的项目中。你可以通过NuGet包管理器来安装ZedGraph库。在Visual Studio中,右击你的项目,选择"管理NuGet程序包",然后搜索并安装ZedGraph。 安装完成后,你可以在代码中引用ZedGraph命名空间,开始使用它的功能。以下是一个示例代码,展示了如何使用ZedGraph创建一个简单的折线图: ```csharp using ZedGraph; public partial class Form1 : Form { public Form1() { InitializeComponent(); // 创建ZedGraph控件 ZedGraphControl zedGraphControl = new ZedGraphControl(); zedGraphControl.Dock = DockStyle.Fill; this.Controls.Add(zedGraphControl); // 创建一个图表对象 GraphPane graphPane = zedGraphControl.GraphPane; // 添加一些样本数据 double[] x = { 1, 2, 3, 4, 5 }; double[] y = { 10, 20, 15, 25, 30 }; // 创建一个曲线对象 LineItem curve = graphPane.AddCurve("折线图", x, y, Color.Blue, SymbolType.Circle); // 定义图表标题和轴标签 graphPane.Title.Text = "示例折线图"; graphPane.XAxis.Title.Text = "X轴"; graphPane.YAxis.Title.Text = "Y轴"; // 刷新图表 zedGraphControl.AxisChange(); } } ``` 以上代码演示了如何创建一个简单的折线图,并添加样本数据。你可以根据自己的需求,进一步定制和修改图表的样式和数据。希望对你有所帮助!如果还有其他问题,请继续提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值