日期:2014-05-17  浏览次数:21608 次

C#怎么绘制曲线图
我在用C#写一个程序,需要根据数据库中查出来的数据,画出相应的曲线图,这怎么弄呀!大侠们,快救救我吧,我都快被这个搞疯了!

------解决方案--------------------
我用的是mschart 4.0,mschart很容易用也很好用, 简单代码如下:

C# code

            chart1.ChartAreas.Clear();
            chart1.Series.Clear();
            chart1.Annotations.Clear();
            chart1.Legends.Clear();
            chart1.Titles.Clear();
            Title t = new Title("委案情况分析");
            t.Alignment = ContentAlignment.MiddleLeft;
            t.TextOrientation = TextOrientation.Stacked;
            t.IsDockedInsideChartArea = false;
            t.Font = new System.Drawing.Font("黑体", 20, FontStyle.Bold);
            chart1.Titles.Add(t);
            ChartArea c1 = new ChartArea("C1");
            c1.AxisX.IntervalType = DateTimeIntervalType.Days;//X轴以天数为间隔
            c1.AxisX.Interval = 1; //X轴刻度的间隔为1
            c1.AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount; 
            c1.AxisX.MajorGrid.Enabled = false; //不显示网格线
            c1.AxisY.MajorGrid.Enabled = false; 
            chart1.ChartAreas.Add(c1);
            Series s1 = new Series("S1");
            s1.ChartType = SeriesChartType.Spline; //画表类型
            Random rnd = new Random();
            for (int i = 0; i < 10; i++)
            {
                DateTime date = DateTime.Now.AddDays(i);
                DataPoint d = new DataPoint(); //要显示的数据
                d.XValue =     date.ToOADate(); //X轴的值,DataPoint只接收double类型
                d.YValues[0] = rnd.NextDouble(); //Y轴的值
                s1.Points.Add(d);
            }
            chart1.Series.Add(s1);

------解决方案--------------------
office 有个一个空间 OWC11或者OWC10

Chart来操作,非常的方便,数据抓出来就可以直接显示
------解决方案--------------------
using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
//添加画图类 
using System.Drawing.Drawing2D; 
using System.Drawing.Imaging; 
using System.Drawing; 
using System.IO; 
using System.Data.SqlClient; 
public partial class Curve_Default : System.Web.UI.Page 

protected void Page_Load(object sender, EventArgs e) 

if (!IsPostBack) 

Get_CurveData(); 


//获取数据 
public void Get_CurveData() 

SqlConnection conn = null; 
try 

conn = CommonFunction.CreateDBTest(); 
conn.Open(); 
SqlCommand cmd = conn.CreateCommand(); 
string sqlStr = "SELECT * FROM CURVE ORDER BY TESTDATE"; 
DataTable dt = CommonFunction.ExecuteDatable(conn, cmd, CommandType.Text, sqlStr, null); 
draw(dt); 

catch (Exception exp) 

Response.Write(exp.Message); 

finally 

if (conn != null) 
conn.Close(); 


public void draw(DataTable dt) 

//取得记录数量 
int count = dt.Rows.Count; 
//记算图表宽度 
int wd = 80 + 20 * (count - 1); 
//设置最小宽度为800 
if (wd < 600) wd = 600; 
//生成Bitmap对像 
Bitmap img = new Bitmap(wd, 400); 
//生成绘图对像 
Graphics g = Graphics.FromImage(img); 
//定义黑色画笔 
Pen Bp = new Pen(Color.Black); 
//定义红色画笔 
Pen Rp = new Pen(Color.Red); 
//定义银灰色画笔 
Pen Sp = new Pen(Color.Silver)