彩票走势图

TeeChart曲线绘制

转帖|其它|编辑:郝浩|2010-10-14 14:15:38.000|阅读 2152 次

概述:最近,为了项目的需要,本人在这段时间学习使用TeeChart控件web曲线绘制,下面把一些有用的代码贴出来,供大家分享。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

  最近,为了项目的需要,本人在这段时间学习使用TeeChart控件web曲线绘制,下面把一些有用的代码贴出来,供大家分享。

Default.aspx
/// <summary>
/// 获得数据集
/// </summary>
/// <param name="sqlStr">传递查询语句</param>
/// <returns>返回数据集</returns>
public static DataSet GetDataSet(string sqlStr)
{
string connstring = System.Configuration .ConfigurationSettings.AppSettings["conStr"];
//string sqlStr = "select * from chart";
SqlDataAdapter da = new SqlDataAdapter(sqlStr, connstring);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
/// <summary>
/// 绘制统计图
/// </summary>
/// <param name="SelectStr">Sql查询语句</param>
private void DrawBar(string SelectStr)
{
Chart chart = WebChart1.Chart;
DataSet DS = new DataSet();
//显示图片的格式,默认PNG
WebChart1.PictureFormat = Steema.TeeChart.Export.PictureFormats.Bitmap;
//设置保存数据形式,默认File,一般选session。Chart.Aspect(外观属性)
WebChart1.TempChart = Steema.TeeChart.Web.TempChartStyle.Session;
//获取显示图片文件
WebChart1.GetChartFile = "GetChart.aspx";
//整个图表的高度
WebChart1.Height = 300;
//整个图表的宽度
WebChart1.Width = 600;

//显示图片的格式,默认PNG
WebChart1.PictureFormat = Steema.TeeChart.Export.PictureFormats.Bitmap;
//设置保存数据形式,默认File,一般选session。Chart.Aspect(外观属性)
WebChart1.TempChart = Steema.TeeChart.Web.TempChartStyle.Session;

//图表底色开始颜色
//WebChart1.Chart.Panel.Gradient.StartColor = Color.Blue;//图表底色开始颜色

//设置图形标题
WebChart1.Chart.Header.Text = "个人每月开销数目柱形图";
//设置X轴标题
WebChart1.Chart.Axes.Bottom.Title.Text = "月份(月)";
//设置Y1轴标题
WebChart1.Chart.Axes.Left.Title.Text = "金额(元)";
WebChart1.Chart.Axes.Left.Labels.ValueFormat = "#M/N";
//参纵坐标轴是否显示
WebChart1.Chart.Axes.Bottom.Grid.Visible = false ;
//横坐标字体倾斜角度0~360
WebChart1.Chart.Axes.Bottom.Labels.Angle= 30;
//图表左边距
WebChart1.Chart.Panel.MarginLeft = 15;
//图例间是否有间隔线
WebChart1.Chart.Legend.DividingLines.Visible = true;
//图形显示比例(好像无反应)
//WebChart1.Chart .Aspect .Zoom = 10;

WebChart1.Dispose();

//是否立体显示
WebChart1.Chart.Aspect.View3D = false;

foreach (Steema.TeeChart.Styles.Series s in chart.Series)

if (styles == 1)
{
//画柱状图
Steema.TeeChart.Styles.Bar sty1 = new Steema.TeeChart.Styles.Bar(WebChart1.Chart);
Steema.TeeChart.Styles.Bar sty2 = new Steema.TeeChart.Styles.Bar(WebChart1.Chart);
chart.Series.Add(sty1);
chart.Series.Add(sty2);
}
if (styles == 2)
{
//画折线图
Steema.TeeChart.Styles.Line sty1 = new Steema.TeeChart.Styles.Line(WebChart1.Chart);
Steema.TeeChart.Styles.Line sty2 = new Steema.TeeChart.Styles.Line(WebChart1.Chart);
chart.Series.Add(sty1);
chart.Series.Add(sty2);
}
if (styles == 3)
{
Steema.TeeChart.Styles.Kagi sty1 = new Steema.TeeChart.Styles.Kagi(WebChart1.Chart);
//Steema.TeeChart.Styles.Kagi sty2 = new Steema.TeeChart.Styles.Kagi(WebChart1.Chart);
chart.Series.Add(sty1);
//chart.Series.Add(sty2);
}

//添加第二个纵坐标
if (YaxixCount == 2)
{
Axis axisY2 = new Axis(false, false, WebChart1.Chart);
chart.Series[1].CustomVertAxis = axisY2;
//sty2.CustomVertAxis = axisY2;
//bar2.CustomVertAxis = axisY2;
WebChart1.Chart.Axes.Custom.Add(axisY2);
axisY2.AxisPen.Color = Color.DarkGreen;//坐标轴颜色
axisY2.Title.Text = "数量";
axisY2.Title.Font.Color = Color.Blue; //坐标轴标题颜色
axisY2.Title.Font.Bold = false;
axisY2.Title.Angle = 90;//旋转90°
axisY2.RelativePosition = -20;
}
//图形颜色
//sty1.ColorEach = false;
//sty2.ColorEach = false;
 

//查询语句
//string SelectStr = "select month,Allcount,fee from chart";

DS.Clear();
try
{
DS = GetDataSet(SelectStr);
}
catch (Exception e)
{
Response.Write(e);
}

if (SeriesCount == 1)
{
chart.Series[0].DataSource = DS.Tables[0];
chart.Series[0].LabelMember = DS.Tables [0].Columns[0].ToString();
chart.Series[0].YValues.DataMember = "Allcount";
}

if (SeriesCount == 2)
{
//第一种方法:(画曲线)
//添加一个series系列
//chart.Series.Add(sty1);
chart.Series[0].DataSource = DS.Tables[0];
chart.Series[0].LabelMember = "month";
chart.Series[0].YValues.DataMember = "Allcount";

//chart.Series.Add(sty2);
chart.Series[1].DataSource = DS.Tables[0];
chart.Series[1].LabelMember = "month";
chart.Series[1].YValues.DataMember = "fee";
}
}

protected void Button3_Click(object sender, EventArgs e) //查询
{
styles = 2;
YaxixCount = 2;
SeriesCount = 2;
string sqlStr = "select month,Allcount,fee from chart where month between " + DropDownList1.SelectedItem.Text.ToString() + " and " + DropDownList2.SelectedItem.Text.ToString() + "";
DrawBar(sqlStr);
}

创建 GetChart.aspx
protected void Page_Load(object sender, EventArgs e)
{
string chartName=Request.QueryString["Chart"];
if (Session[chartName]!=null)
{
System.IO.MemoryStream chartStream = new System.IO.MemoryStream();
chartStream=((System.IO.MemoryStream)Session[chartName]);
Response.OutputStream.Write(chartStream.ToArray(),0,(int)chartStream.Length);
chartStream.Close();
Session.Remove(chartName);
}
}

   

慧都2010促销季开幕,TeeChart for .NET 8折促销!详情咨询:400-700-1020023-66090381活动详情://pclwef.cn/zh-CN/Products_cn/TeeChart_chinese.html


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:网络转载

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP