用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/

原文地址:https://www.cnblogs.com/arxive/p/6913743.html