用ZedGraph控件作图圆
转自原文 用ZedGraph控件作图圆
用ZedGraph控件绘制圆
各位:
我想利用第三方控ZedGraph在WinForm窗体中绘制图形如,圆,填充圆,只是简单的圆图形,但一直没有找到相应的方法,网上的资料都是些绘制图表,拆线,圆饼类。对我有些不太适用。
现求教各位。谢谢。主要是看重此软件的缩放功能,实时性比较好,因为我是做工业UI的。
Add an EllipseItem to the graph, then add the following code to your ReSize event for the form:
// Fix the ellipseItem to a perfect circle by using a fixed height, but a variable
// width
EllipseItem ellipse = zedGraphControl1.GraphPane.GraphItemList[0] as EllipseItem;
if ( ellipse != null )
{
GraphPane myPane = zedGraphControl1.GraphPane;
float dx = (float) ( myPane.XAxis.Max - myPane.XAxis.Min );
float dy = (float) ( myPane.YAxis.Max - myPane.YAxis.Min );
float xPix = myPane.AxisRect.Width * ellipse.Location.Width / dx;
float yPix = myPane.AxisRect.Height * ellipse.Location.Height / dy;
ellipse.Location.Width *= yPix / xPix;
// alternatively, use this to vary the height but fix the width
// (comment out the width line above)
//ellipse.Location.Height *= xPix / yPix;
}
This will give you a true circle, with a fixed height and a variable width as you resize the graph to any size.
John
以上是在一英文网站上找到一点点相关资料,试了一下,不行,主要是“EllipseItem ”类型没有,不知本人水平有限还是怎么的,没弄出现。 图形 控件
[解决办法]
就只画圆的话,用得着第三方控件吗?
[解决办法]
这里有人写不错还有三角函数例子
[解决办法]
1. 设置坐标范围都为正数就可以了,设置后不要忘记刷新:
zedGraphControl1.GraphPane.YAxis.Scale.Min = 0;
zedGraphControl1.GraphPane.XAxis.Scale.Min = 0;
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
zedGraphControl1.Refresh();
2. 这个需要从GraphObj派生,覆盖Draw方法自己画,比如:
public class MyEllipseObj : EllipseObj
{
public MyEllipseObj(){}
public MyEllipseObj(double x, double y, double width, double height) : base(x, y, width, height){}
public MyEllipseObj(double x, double y, double width, double height, Color borderColor, Color fillColor)
: base(x, y, width, height, borderColor, fillColor) {} public override void Draw(Graphics g, PaneBase pane, float scaleFactor)
{
if (pane is GraphPane && ((GraphPane)pane).Chart != null)
{
var oldClip = g.Clip.Clone();
g.SetClip((pane as GraphPane).Chart.Rect);
base.Draw(g, pane, scaleFactor);
g.Clip = oldClip;
}
else
base.Draw(g, pane, scaleFactor);
}
}
然后用刀EllipseObj的地方改成MyEllipseObj
3. 同样还是调整坐标轴的设置:
zedGraphControl1.GraphPane.YAxis.Scale.MajorStep = 0.2; // 调整刻度间距
zedGraphControl1.GraphPane.YAxis.Scale.Max = 2; // 调整坐标轴最大值
4. 用饼图可以实现:
http://zedgraph.dariowiz.com/indexe246.html?title=Pie_Chart_Demo
5. 可以。基本上所有图形对象都可以派生重写Draw绘图方法,比如:
public class MyGraphPane : GraphPane
{
public override void Draw(Graphics g)
{
base.Draw(g); // 调用基类画图方法画出原来的图形
// 添加你自己的画图放啊
}
}
然后用的时候把GraphPane替换成派生的MyGraphPane
var myPane = new MyGraphPen();
zedGraphControl1.GraphPane = myPane;
===============
很多问题网上都有现成的解答,多看看帮助和论坛讨论
http://zedgraph.dariowiz.com/
最新文章
- 370. Range Addition
- 在VS中操作Mysql数据库
- 8种效果实例-jQuery anoSlide 焦点图轮播
- 构造函数的return返回值
- Redis__WindowsServer主从服务部署及调用实例
- WebRTC的学习(二)
- Sql日期时间格式转换;取年 月 日,函数:DateName()、DATEPART()
- Python模块(Module)
- PHP 简易读取文件目录下的文件,生成css spirte图片
- 漫话Unity3D(三)
- Eclipse 安装最新SVN插件
- zepto的源代码注释(转)
- LVS的原理介绍
- javascript的面向对象详解
- 关于php的一些安全知识
- DirectX11 With Windows SDK--23 立方体映射:动态天空盒的实现
- 小程序bindtap和cachetap的区别
- nvwgf2umx.dll 显卡崩溃问题尝试修复
- 【app】Appium-desktop界面介绍
- oracle如何通过cmd导出某个用户下的所有表