各位:
我想利用第三方控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 ”类型没有,不知本人水平有限还是怎么的,没弄出现。图形控件
我想利用第三方控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 ”类型没有,不知本人水平有限还是怎么的,没弄出现。图形控件
你没看清楚我的帖子,我对图形实时性,及缩放有要求,还有就是将来可能也要做拆线类的图形,所以考虑用ZedGraph控件
我知道用GDI+可以做。
这个是用GDI+做的,我想用ZedGraph.谢谢。
ellipse.Location.CoordinateFrame = CoordType.AxisXYScale;
zedGraphControl1.GraphPane.GraphObjList.Add(ellipse);
前两个值0和0.5就是指x,y坐标值,圆心位置
有什么属性能让点击BUTTON事件后直接显示在控制界面中的方法,不用放大,也不用缩小的那种
2:能否加QQ 398591947,我给你截张图,你能看的明白点。谢谢
zedGraphControl1.Refresh();
哦,这个位置坐标X Y在我昨天晚上大量的数据统计下,已经得出来了,不过还是要感谢你。最后还有几个问题想请教下:
1: 怎样取消图形中的中轴线,及XY负轴,也就是在放大时,不想显示XY负轴坐标。
2:怎样控制图形在放大时不超出显示区域。
3: 怎样调整刻度线显示区域的大小 (你给的图形中“文字Y轴”显示区域太大多大,想调小点。)
非常感谢
哦,这个位置坐标X Y在我昨天晚上大量的数据统计下,已经得出来了,不过还是要感谢你。最后还有几个问题想请教下:
1: 怎样取消图形中的中轴线,及XY负轴,也就是在放大时,不想显示XY负轴坐标。
2:怎样控制图形在放大时不超出显示区域。
3: 怎样调整刻度线显示区域的大小 (你给的图形中“文字Y轴”显示区域太大多大,想调小点。)
非常感谢
再补充一个:能否在图表中绘制半圆,1/4,1/7圆等圆弧(也就是通过坐标值来控制圆弧的弧度大小),我知道在GDI+中很容易完成这个功能,不知ZedGraph有这个功能没?同时弱弱的问下,能否在ZedGraph中调用GDI+中的方法,然后在ZedGraph图表中生成我想要的图形,如果可以的话,给点代码提示。谢谢。
如果最上面3个问题比较麻烦的话,就不用回答了,主要就最后一个。(问题问的有点多,自己觉得有点不好意思了啊)
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的地方改成MyEllipseObj3. 同样还是调整坐标轴的设置:
zedGraphControl1.GraphPane.YAxis.Scale.MajorStep = 0.2; // 调整刻度间距
zedGraphControl1.GraphPane.YAxis.Scale.Max = 2; // 调整坐标轴最大值4. 用饼图可以实现:
http://zedgraph.dariowiz.com/indexe246.html?title=Pie_Chart_Demo5. 可以。基本上所有图形对象都可以派生重写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/