C# 中如何在pictureBox中做一坐标轴,最好能改变范围
2个回答
展开全部
其实很简单,就是计算量比较大,需要制作一个类,如果真的需要很详细的Q我523740321.简单的方法是:
//画X轴和Y轴的基本部分,包括间隔、方向箭头
public void DrawXY(ref Graphics g, Panel picbox,Color color)
{
Pen pen = new Pen(Color.Black , 2);//画笔
SolidBrush sb = new SolidBrush(Color.Green);//画刷
//X轴上的方向箭头,实际上是绘制了一个三角形
Point[] xpts = new Point[3]{
new Point(picbox.Width-35,picbox.Height-32),
new Point(picbox.Width-35,picbox.Height-28),
new Point(picbox.Width-30,picbox.Height-30)
};
g.DrawLine(pen, 50, picbox.Height - 30, picbox.Width - 30, picbox.Height - 30);//绘制X坐标轴
g.DrawPolygon(pen, xpts);//绘制X轴的方向箭头
g.DrawString("时间", new Font("宋体", 9), sb, picbox.Width - 1, picbox.Height - 1);//标注X轴
//Y轴的箭头,实际上是绘制了一个三角形
Point[] ypts = new Point[3]{
new Point(48,75),
new Point(50,70),
new Point(52,75) };
g.DrawLine(pen, 50, picbox.Height - 30, 50, 70);
g.DrawPolygon(pen, ypts);
//根据颜色绘制X轴标注
//
if (color == System.Drawing.Color.Green )
g.DrawString("单位:人数", new Font("宋体", 9), sb, 50, 50);
if (color==System.Drawing.Color.Red)
g.DrawString("单位:票数", new Font("宋体", 9), sb, 50, 50);
if (color==System.Drawing.Color.Blue)
g.DrawString("单位:人数/票数", new Font("宋体", 9), sb, 50, 50);
//绘制图标
Pen demo_Rect = new Pen(Color.Black, 1);
Pen demo_RQ = new Pen(Color.Red , 3);
Pen demo_SLE = new Pen(Color.Green, 3);
//g.DrawLine(demo_RQ, picbox.Width/2 - 100, 50, picbox.Width/2 - 110, 50);
//g.DrawString("人数", new Font("宋体", 9), sb, picbox.Width / 2 - 112, 50);
//g.DrawRectangle(demo_Rect, picbox.Width / 2 - 20, 50, 120, 20);
g.DrawRectangle(demo_Rect, picbox.Width - 170, 50, 120, 20);
//进站客流
g.DrawLine(demo_RQ, picbox.Width - 160, 60, picbox.Width -150 , 60);
g.DrawEllipse(demo_RQ, picbox.Width -150, 58, 4, 4);
g.DrawLine(demo_RQ, picbox.Width-144, 60, picbox.Width -136, 60);
g.DrawString("人数", new Font("宋体", 9), sb, picbox.Width-138 , 55);
//票箱
g.DrawLine(demo_SLE , picbox.Width -110, 60, picbox.Width -100, 60);
g.DrawEllipse(demo_SLE, picbox.Width -100, 58, 4, 4);
g.DrawLine(demo_SLE, picbox.Width -100, 60, picbox.Width-86, 60);
g.DrawString("票数", new Font("宋体", 9), sb, picbox.Width -84, 55);
}
public float SetXAxis_Unit(ref Graphics g, Panel picbox, string[] strtime, int xmark, int X_scale)
{
//xmark = xmark / 10;//因为i是用来计数画每一条线,所以最好用10的整数倍
Pen p1 = new Pen(Color.Black, 1);//用来画线条
Pen p2 = new Pen(Color.Blue, 2);//用来画每隔3个线条出现的粗线条
Pen p3 = new Pen(Color.Gray, 1);//用来画虚线
// p3.DashStyle = DashStyle.Dot ;
p3.DashStyle = DashStyle.DashDotDot;
SolidBrush sb = new SolidBrush(Color.Blue);//用来填充标注字的颜色
int less = 1;
float xt = 50, yt = picbox.Height - 30, xb = 50, yb = picbox.Height - 34;//第一条线的起始位置
int j = new int();
string tempx = null;
int i = 0;
int LessRound = 1;
if (X_scale == 3)
LessRound = 2;
for (i = 0; i < ((strtime.Length * X_scale) - LessRound); i += 1)
//for (int i = 0; i < ((strtime.Length * X_scale) - 1); i += 1)
{
g.DrawLine(p1, xt + i * xmark, yt, xb + i * xmark, yb);
//定义虚线并画网格
g.DrawLine(p3, xt + i * xmark, yt, xb + i * xmark, 80);
if (i == 0)
{
j = (int)i / X_scale;
g.DrawLine(p2, xt + i * xmark, yt, xb + i * xmark, yb - 4);
tempx = strtime[j];
g.DrawString(tempx, new Font("宋体", 9), sb, xb + i * xmark - 20, yb + 8);
}
if ((i % X_scale == 0) && (i != 0))//一个大的间隔,每隔3个像素出现一个
{
j = (int)i / X_scale;
g.DrawLine(p2, xt + i * xmark, yt, xb + i * xmark, yb - 4);
tempx = strtime[j];
g.DrawString(tempx, new Font("宋体", 9), sb, xb + i * xmark - 20, yb + 8);
}
if (tempx == strtime[strtime.Length - 1])
{
xt = xb + i * xmark;
break;
}
}
if (i ==13)
i = 12;
xt = xb + i * xmark;
return xt;
}
public void SetYAxis_Unit (ref Graphics g, Panel picbox, int ymark, int scale,float MaxX )
{
Pen p1 = new Pen(Color.Black, 1);//用来画小线条
Pen p2 = new Pen(Color.Blue, 2);//用来画每隔5个小线条出现的粗线条
SolidBrush sb = new SolidBrush(Color.Blue);//用来填充标注字的颜色
Pen p3 = new Pen(Color.Gray, 1);//用来画虚线
//p3.DashStyle = DashStyle.Dot;
p3.DashStyle = DashStyle.DashDotDot;
float xt = 50, yt = picbox.Height - 30, xb = MaxX, yb = picbox.Height - 30;//第一条线的起始位置
for (int i = 0; i < ((picbox.Height - 100) / ymark); i += 1)
{
g.DrawLine(p1, xt, yt - i * ymark, 55, yb - i * ymark);
g.DrawLine(p3, xt, yb - i * ymark, xb , yb - i * ymark);
if ((i % 5 == 0) && (i != 0))//一个大的间隔,每隔5个像素出现一个
{
//g.DrawLine(p2, xt, yt - i * ymark, xb, yb - i * ymark);//每隔10个像素画一条直线
g.DrawLine(p2, 50, yt - i * ymark, 60, yb - i * ymark);
string tempy = (i * scale).ToString();
g.DrawString(tempy, new Font("宋体", 9), sb, 18, yb - i * ymark - 8);
}
}
//计算Y轴的最大值设置为60个格的时候
FormNumOfCustomers.pub_lastY = picbox.Height - 60 * ymark;
}
}
//画X轴和Y轴的基本部分,包括间隔、方向箭头
public void DrawXY(ref Graphics g, Panel picbox,Color color)
{
Pen pen = new Pen(Color.Black , 2);//画笔
SolidBrush sb = new SolidBrush(Color.Green);//画刷
//X轴上的方向箭头,实际上是绘制了一个三角形
Point[] xpts = new Point[3]{
new Point(picbox.Width-35,picbox.Height-32),
new Point(picbox.Width-35,picbox.Height-28),
new Point(picbox.Width-30,picbox.Height-30)
};
g.DrawLine(pen, 50, picbox.Height - 30, picbox.Width - 30, picbox.Height - 30);//绘制X坐标轴
g.DrawPolygon(pen, xpts);//绘制X轴的方向箭头
g.DrawString("时间", new Font("宋体", 9), sb, picbox.Width - 1, picbox.Height - 1);//标注X轴
//Y轴的箭头,实际上是绘制了一个三角形
Point[] ypts = new Point[3]{
new Point(48,75),
new Point(50,70),
new Point(52,75) };
g.DrawLine(pen, 50, picbox.Height - 30, 50, 70);
g.DrawPolygon(pen, ypts);
//根据颜色绘制X轴标注
//
if (color == System.Drawing.Color.Green )
g.DrawString("单位:人数", new Font("宋体", 9), sb, 50, 50);
if (color==System.Drawing.Color.Red)
g.DrawString("单位:票数", new Font("宋体", 9), sb, 50, 50);
if (color==System.Drawing.Color.Blue)
g.DrawString("单位:人数/票数", new Font("宋体", 9), sb, 50, 50);
//绘制图标
Pen demo_Rect = new Pen(Color.Black, 1);
Pen demo_RQ = new Pen(Color.Red , 3);
Pen demo_SLE = new Pen(Color.Green, 3);
//g.DrawLine(demo_RQ, picbox.Width/2 - 100, 50, picbox.Width/2 - 110, 50);
//g.DrawString("人数", new Font("宋体", 9), sb, picbox.Width / 2 - 112, 50);
//g.DrawRectangle(demo_Rect, picbox.Width / 2 - 20, 50, 120, 20);
g.DrawRectangle(demo_Rect, picbox.Width - 170, 50, 120, 20);
//进站客流
g.DrawLine(demo_RQ, picbox.Width - 160, 60, picbox.Width -150 , 60);
g.DrawEllipse(demo_RQ, picbox.Width -150, 58, 4, 4);
g.DrawLine(demo_RQ, picbox.Width-144, 60, picbox.Width -136, 60);
g.DrawString("人数", new Font("宋体", 9), sb, picbox.Width-138 , 55);
//票箱
g.DrawLine(demo_SLE , picbox.Width -110, 60, picbox.Width -100, 60);
g.DrawEllipse(demo_SLE, picbox.Width -100, 58, 4, 4);
g.DrawLine(demo_SLE, picbox.Width -100, 60, picbox.Width-86, 60);
g.DrawString("票数", new Font("宋体", 9), sb, picbox.Width -84, 55);
}
public float SetXAxis_Unit(ref Graphics g, Panel picbox, string[] strtime, int xmark, int X_scale)
{
//xmark = xmark / 10;//因为i是用来计数画每一条线,所以最好用10的整数倍
Pen p1 = new Pen(Color.Black, 1);//用来画线条
Pen p2 = new Pen(Color.Blue, 2);//用来画每隔3个线条出现的粗线条
Pen p3 = new Pen(Color.Gray, 1);//用来画虚线
// p3.DashStyle = DashStyle.Dot ;
p3.DashStyle = DashStyle.DashDotDot;
SolidBrush sb = new SolidBrush(Color.Blue);//用来填充标注字的颜色
int less = 1;
float xt = 50, yt = picbox.Height - 30, xb = 50, yb = picbox.Height - 34;//第一条线的起始位置
int j = new int();
string tempx = null;
int i = 0;
int LessRound = 1;
if (X_scale == 3)
LessRound = 2;
for (i = 0; i < ((strtime.Length * X_scale) - LessRound); i += 1)
//for (int i = 0; i < ((strtime.Length * X_scale) - 1); i += 1)
{
g.DrawLine(p1, xt + i * xmark, yt, xb + i * xmark, yb);
//定义虚线并画网格
g.DrawLine(p3, xt + i * xmark, yt, xb + i * xmark, 80);
if (i == 0)
{
j = (int)i / X_scale;
g.DrawLine(p2, xt + i * xmark, yt, xb + i * xmark, yb - 4);
tempx = strtime[j];
g.DrawString(tempx, new Font("宋体", 9), sb, xb + i * xmark - 20, yb + 8);
}
if ((i % X_scale == 0) && (i != 0))//一个大的间隔,每隔3个像素出现一个
{
j = (int)i / X_scale;
g.DrawLine(p2, xt + i * xmark, yt, xb + i * xmark, yb - 4);
tempx = strtime[j];
g.DrawString(tempx, new Font("宋体", 9), sb, xb + i * xmark - 20, yb + 8);
}
if (tempx == strtime[strtime.Length - 1])
{
xt = xb + i * xmark;
break;
}
}
if (i ==13)
i = 12;
xt = xb + i * xmark;
return xt;
}
public void SetYAxis_Unit (ref Graphics g, Panel picbox, int ymark, int scale,float MaxX )
{
Pen p1 = new Pen(Color.Black, 1);//用来画小线条
Pen p2 = new Pen(Color.Blue, 2);//用来画每隔5个小线条出现的粗线条
SolidBrush sb = new SolidBrush(Color.Blue);//用来填充标注字的颜色
Pen p3 = new Pen(Color.Gray, 1);//用来画虚线
//p3.DashStyle = DashStyle.Dot;
p3.DashStyle = DashStyle.DashDotDot;
float xt = 50, yt = picbox.Height - 30, xb = MaxX, yb = picbox.Height - 30;//第一条线的起始位置
for (int i = 0; i < ((picbox.Height - 100) / ymark); i += 1)
{
g.DrawLine(p1, xt, yt - i * ymark, 55, yb - i * ymark);
g.DrawLine(p3, xt, yb - i * ymark, xb , yb - i * ymark);
if ((i % 5 == 0) && (i != 0))//一个大的间隔,每隔5个像素出现一个
{
//g.DrawLine(p2, xt, yt - i * ymark, xb, yb - i * ymark);//每隔10个像素画一条直线
g.DrawLine(p2, 50, yt - i * ymark, 60, yb - i * ymark);
string tempy = (i * scale).ToString();
g.DrawString(tempy, new Font("宋体", 9), sb, 18, yb - i * ymark - 8);
}
}
//计算Y轴的最大值设置为60个格的时候
FormNumOfCustomers.pub_lastY = picbox.Height - 60 * ymark;
}
}
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询