开发者

c# can you get position from axis without having a form?

I have a WinForm application that I would like to convert to a service. It has two mscharts on it. I don't need to see those charts anymore because the application creat开发者_开发问答es bitmaps out of them. I am drawing a line on one chart depending on data from another chart, like this:

// Get Graphics object from chart
Graphics graph = e.ChartGraphics.Graphics;

// Convert X and Y values to screen position
float pixelYMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, CreatininePoint.YValues[0]);
float pixelXMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, CreatininePoint.XValue);
float pixelYMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, CreatininePoint.YValues[0]-20);
float pixelXMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, CreatininePoint.XValue);

PointF point1 = PointF.Empty;
PointF point2 = PointF.Empty;

// Set Maximum and minimum points
point1.X = pixelXMax;
point1.Y = pixelYMax-10;
point2.X = pixelXMin;
point2.Y = 84;

// Convert relative coordinates to absolute coordinates.
point1 = e.ChartGraphics.GetAbsolutePoint(point1);
point2 = e.ChartGraphics.GetAbsolutePoint(point2);

float[] dashValues = { 4,2 };
Pen blackPen = new Pen(Color.Black, 1);
blackPen.DashPattern = dashValues;
//e.Graphics.DrawLine(blackPen, new Point(5, 5), new Point(405, 5));
//graph.DrawLine(blackPen, point1, point2);

// Draw connection line
graph.DrawLine(new Pen(Color.Black, 2), point2, point1);

// Create string to draw.
//String drawString = creatininept + " ng/mL";
String drawString = "67 ng/mL";

// Create font and brush.
Font drawFont = new Font("Arial", 7);
SolidBrush drawBrush = new SolidBrush(Color.Black);

// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF(point1.X,point1.Y+5);

// Draw string to screen.
graph.DrawString(drawString, drawFont, drawBrush, drawPoint);

is it possible to do this without having a form so that we can have a service running?


Bitmap canvas = new Bitmap(600, 480);
Graphics graph = Graphics.FromImage(canvas);

.. then proceed with drawing on graph.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜