社区
图表区
帖子详情
如何绘制折线图
li8136
2007-01-25 10:26:45
我有一个二维数组,想根据此数组绘制折线图,请问大侠们该怎么办?
...全文
1645
4
打赏
收藏
如何绘制折线图
我有一个二维数组,想根据此数组绘制折线图,请问大侠们该怎么办?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
liuyactive
2007-01-27
打赏
举报
回复
class ChartComp
{
public Bitmap curBitmap;
public ArrayList ptsArrayList =
new ArrayList();
public float X0 = 0, Y0 = 0;
public float chartX, chartY;
public Color chartColor = Color.Gray;
// chartType: 1=Line, 2=Pie, 3=Bar.
// For future use only.
public int chartType = 1;
private int Width, Height;
private Graphics g;
private Page curPage;
struct ptStructure
{
public float x;
public float y;
public Color clr;
}
// ChartComp constructor
public ChartComp(int cType, Color cColor,
int cWidth, int cHeight, Page cPage)
{
Width = cWidth;
Height = cHeight;
chartX = cWidth;
chartY = cHeight;
curPage = cPage;
chartType = cType;
chartColor = cColor;
curBitmap = new Bitmap(Width, Height);
g = Graphics.FromImage(curBitmap);
}
// Destructor. Disposes of objects.
~ChartComp()
{
curBitmap.Dispose();
g.Dispose();
}
// InsertPoint method. Adds a point
// to the array.
public void InsertPoint(int xPos,
int yPos, Color clr)
{
ptStructure pt;
pt.x = xPos;
pt.y = yPos;
pt.clr = clr;
// Add the point to the array
ptsArrayList.Add(pt);
}
public void InsertPoint(int position,
int xPos, int yPos, Color clr)
{
ptStructure pt;
pt.x = xPos;
pt.y = yPos;
pt.clr = clr;
// Add the point to the array
ptsArrayList.Insert(position, pt);
}
// Draw methods
public void DrawChart()
{
int i;
float x, y, x0, y0;
curPage.Response.ContentType="image/jpeg";
g.SmoothingMode = SmoothingMode.HighQuality;
g.FillRectangle(new SolidBrush(chartColor),
0, 0, Width, Height);
int chWidth = Width-80;
int chHeight = Height-80;
g.DrawRectangle(Pens.Black,
40, 40, chWidth, chHeight);
g.DrawString("GDI+ Chart", new Font("arial",14),
Brushes.Black, Width/3, 10);
// Draw x- and y-axis line, points, positions
for(i=0; i<=5; i++)
{
x = 40+(i*chWidth)/5;
y = chHeight+40;
string str = (X0 + (chartX*i/5)).ToString();
g.DrawString(str, new Font("Verdana",10),
Brushes.Blue, x-4, y+10);
g.DrawLine(Pens.Black, x, y+2, x, y-2);
}
for(i=0; i<=5; i++)
{
x = 40;
y = chHeight+40-(i*chHeight/5);
string str = (Y0 + (chartY*i/5)).ToString();
g.DrawString(str, new Font("Verdana",10),
Brushes.Blue, 5, y-6);
g.DrawLine(Pens.Black, x+2, y, x-2, y);
}
// Transform coordinates so that point (0,0)
// is in the lower left corner
g.RotateTransform(180);
g.TranslateTransform(-40, 40);
g.ScaleTransform(-1, 1);
g.TranslateTransform(0, -(Height));
// Draw all points from the array
ptStructure prevPoint = new ptStructure();
foreach(ptStructure pt in ptsArrayList)
{
x0 = chWidth*(prevPoint.x-X0)/chartX;
y0 = chHeight*(prevPoint.y-Y0)/chartY;
x = chWidth*(pt.x-X0)/chartX;
y = chHeight*(pt.y-Y0)/chartY;
g.DrawLine(Pens.Black, x0, y0, x, y);
g.FillEllipse(new SolidBrush(pt.clr),
x0-5, y0-5, 10, 10);
g.FillEllipse(new SolidBrush(pt.clr),
x-5, y-5, 10, 10);
prevPoint = pt;
}
curBitmap.Save(curPage.Response.OutputStream,
ImageFormat.Jpeg);
}
}
private void Button1_Click(object sender,
System.EventArgs e)
{
// Get the chart background color
Color clr = Color.FromName(TextBox3.Text);
// Create a ChartComp object
ChartComp chart =
new ChartComp(1, clr, 400, 300, this.Page);
chart.X0 = 0;
chart.Y0= 0;
chart.chartX = Convert.ToInt16(TextBox1.Text);
chart.chartY = Convert.ToInt16(TextBox2.Text);
// Add points to the chart
chart.InsertPoint(Convert.ToInt16(TextBox4.Text),
Convert.ToInt16(TextBox5.Text),
Color.FromName(TextBox6.Text) );
chart.InsertPoint(Convert.ToInt16(TextBox7.Text),
Convert.ToInt16(TextBox8.Text),
Color.FromName(TextBox9.Text) );
chart.InsertPoint(Convert.ToInt16(TextBox10.Text),
Convert.ToInt16(TextBox11.Text),
Color.FromName(TextBox12.Text) );
chart.InsertPoint(Convert.ToInt16(TextBox13.Text),
Convert.ToInt16(TextBox14.Text),
Color.FromName(TextBox15.Text) );
chart.InsertPoint(Convert.ToInt16(TextBox16.Text),
Convert.ToInt16(TextBox17.Text),
Color.FromName(TextBox18.Text) );
// Draw chart
chart.DrawChart();
}
根据这个就能绘出
lxmfll2000
2007-01-26
打赏
举报
回复
用RDLC。
dahuzizyd
2007-01-26
打赏
举报
回复
ZedGraph:
http://www.cnblogs.com/dahuzizyd/archive/2007/01/16/ZedGraph_Dynamic_Line_Chart.html
C++绘图类,可以
绘制
折线图
,饼状图,条形图等
我一直想如果VC++能像MATLAB一样...现在我在网上找到了这个绘图类,非常好使,完美实现了MATLAB一样绘图功能,可
绘制
折线图
、饼状图、条形图等。内部有类的源码和演示例程,我调试通过了,大家放心使用!感谢原作者!
matlab根据excel画
折线图
和柱状图
根据excel内容画
折线图
和柱状图,具体可参考:https://blog.csdn.net/u010637291/article/details/117189249(其对应的代码和数据)
PyQt5:QtCharts
绘制
折线图
本资源为:pyqtchart
绘制
简单
折线图
源码<源码资源包不可以更换:代码段 self.charView.chart().setAxisX(self.x_Aix) #设置x轴属性 self.charView.chart().setAxisY(self.y_Aix) #设置y轴属性 注释> ,将博客中的...
QtChart
绘制
折线图
QtChart
绘制
折线图
绘制
折线图
,MFC,ChartCtrl
绘制
折线图
,MFC,ChartCtrl
图表区
4,816
社区成员
14,134
社区内容
发帖
与我相关
我的任务
图表区
.NET技术 图表区
复制链接
扫一扫
分享
社区描述
.NET技术 图表区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章