zedGraph画饼图

public void CreateChart(ZedGraphControl zgc)
        {
            GraphPane myPane = zgc.GraphPane;

            // 设置图表的标题和标题的样式
            myPane.Title.Text = "2004 ZedGraph Sales by Region\n($M)";
            myPane.Title.FontSpec.IsItalic = true;
            myPane.Title.FontSpec.Size = 24f;
            myPane.Title.FontSpec.Family = "Times New Roman";

            // 设置背景色
            myPane.Fill = new Fill(Color.White, Color.Goldenrod, 45.0f);
            // 设置图表的颜色填充,如果设置为FillType.None,则填充色和背景色相同
            myPane.Chart.Fill.Type = FillType.None;

            // 设置图例的大小和位置
            myPane.Legend.Position = LegendPos.Float;
            myPane.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction,
            AlignH.Right, AlignV.Top);
            myPane.Legend.FontSpec.Size = 10f;
            myPane.Legend.IsHStack = false;

            /*
            * 设置饼图的各个部分
            * AddPieSlice方法的参数是 value值, 颜色,渐变色,渐变大小,离开中心点的距离,名称
            */
            PieItem segment1 = myPane.AddPieSlice(20, Color.Navy, Color.White, 45f, 0, "North");
            PieItem segment3 = myPane.AddPieSlice(30, Color.Purple, Color.White, 45f, 0, "East");
            PieItem segment4 = myPane.AddPieSlice(10.21, Color.LimeGreen, Color.White, 45f, 0, "West");
            PieItem segment2 = myPane.AddPieSlice(40, Color.SandyBrown, Color.White, 45f, 0.2, "South");
            PieItem segment6 = myPane.AddPieSlice(250, Color.Red, Color.White, 45f, 0, "Europe");
            PieItem segment7 = myPane.AddPieSlice(50, Color.Blue, Color.White, 45f, 0.2, "Pac Rim");
            PieItem segment8 = myPane.AddPieSlice(400, Color.Green, Color.White, 45f, 0, "South America");
            PieItem segment9 = myPane.AddPieSlice(50, Color.Yellow, Color.White, 45f, 0.2, "Africa");

            zgc.AxisChange();
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ZedGraph饼图、条形图和饼图Demo源码 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轴
要使用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(); ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值