如何绘制折线图
我有一个二维数组,想根据此数组绘制折线图,请问大侠们该怎么办?
------解决方案--------------------http://www.wave12.com/web/SigCon.asp?bCate=41&sCateName=折线图&ID=151&CateName=wsChart4.5(DLL)
------解决方案--------------------ZedGraph:
http://www.cnblogs.com/dahuzizyd/archive/2007/01/16/ZedGraph_Dynamic_Line_Chart.html
------解决方案--------------------用RDLC。
------解决方案--------------------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;