小女子初来,属于菜鸟级别的,今天做一个项目中,发现一个问题,就是用OWC11画折线图,从数据库里读得数据,数据都显示正确。横轴:时间,Y轴:水温。可是就是没有连起来的折线啊?急死了,盼望各位指点。不胜感激~~主要代码如下: if (!IsPostBack)
{
string strSeriesName = "图例1";
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=siat;" +
"UID=root;" +
"PASSWORD=root;" +
"OPTION=3";
//Connect to MySQL using Connector/ODBC
OdbcConnection MyConnection = new OdbcConnection(MyConString);
MyConnection.Open();
OdbcDataAdapter sda = new OdbcDataAdapter("select id ,submit_datetime ,water_level from sensor_information order by id desc limit 20", MyConnection);
DataSet ds = new DataSet();
sda.Fill(ds); //存放时间
string[] publish_datetime = new string[20];
//存放水温
string[] temp = new string[20];
//string[] id = new string[1024];
//为数组赋值
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
publish_datetime [i] = ds.Tables[0].Rows[i][1].ToString(); temp[i] =ds.Tables[0].Rows[i][2].ToString();
}
//创建ChartSpace对象来放置图表
ChartSpace laySpace = new ChartSpaceClass(); //在ChartSpace对象中添加图表
ChChart InsertChart = laySpace.Charts.Add(0); //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到
InsertChart.Type = ChartChartTypeEnum.chChartTypeLine;//折线图
//指定图表是否需要图例标注
InsertChart.HasLegend = false ;
InsertChart.HasTitle = true;//为图表添加标题
InsertChart.Title.Caption = "水温随时间变化显示图";//标题名称 //为x,y轴添加图示说明
InsertChart.Axes[0].HasTitle = true;
InsertChart.Axes[0].Title.Caption = "时间";//
InsertChart.Axes[1].HasTitle = true; InsertChart.Axes[1].Title.Caption = "水位";
//为x轴指定特定字符串,以便显示数据
string strXdata = String.Empty;
string strYdata = String.Empty;
for(int j=0;j<20;j++)
{
strXdata = publish_datetime [j] + "/t";
strYdata = temp[j] + "/t";
//添加一个series系列
InsertChart.SeriesCollection.Add(0); //给定series系列的名字
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName); //给定分类
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata); //给定值
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);
Microsoft .Office .Interop .Owc11.ChDataLabels dl=InsertChart.SeriesCollection[0].DataLabelsCollection.Add();
dl.HasValue = true;
}
//输出文件.
string strAbsolutePath = (Server.MapPath(".")) + "//ShowData.gif";
laySpace.ExportPicture(strAbsolutePath, "GIF", 800,600); //创建GIF文件的相对路径.
string strRelativePath = "./ShowData.gif"; //把图片添加到placeholder中,并在页面上显示
string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));
}
}
{
string strSeriesName = "图例1";
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=siat;" +
"UID=root;" +
"PASSWORD=root;" +
"OPTION=3";
//Connect to MySQL using Connector/ODBC
OdbcConnection MyConnection = new OdbcConnection(MyConString);
MyConnection.Open();
OdbcDataAdapter sda = new OdbcDataAdapter("select id ,submit_datetime ,water_level from sensor_information order by id desc limit 20", MyConnection);
DataSet ds = new DataSet();
sda.Fill(ds); //存放时间
string[] publish_datetime = new string[20];
//存放水温
string[] temp = new string[20];
//string[] id = new string[1024];
//为数组赋值
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
publish_datetime [i] = ds.Tables[0].Rows[i][1].ToString(); temp[i] =ds.Tables[0].Rows[i][2].ToString();
}
//创建ChartSpace对象来放置图表
ChartSpace laySpace = new ChartSpaceClass(); //在ChartSpace对象中添加图表
ChChart InsertChart = laySpace.Charts.Add(0); //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到
InsertChart.Type = ChartChartTypeEnum.chChartTypeLine;//折线图
//指定图表是否需要图例标注
InsertChart.HasLegend = false ;
InsertChart.HasTitle = true;//为图表添加标题
InsertChart.Title.Caption = "水温随时间变化显示图";//标题名称 //为x,y轴添加图示说明
InsertChart.Axes[0].HasTitle = true;
InsertChart.Axes[0].Title.Caption = "时间";//
InsertChart.Axes[1].HasTitle = true; InsertChart.Axes[1].Title.Caption = "水位";
//为x轴指定特定字符串,以便显示数据
string strXdata = String.Empty;
string strYdata = String.Empty;
for(int j=0;j<20;j++)
{
strXdata = publish_datetime [j] + "/t";
strYdata = temp[j] + "/t";
//添加一个series系列
InsertChart.SeriesCollection.Add(0); //给定series系列的名字
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName); //给定分类
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata); //给定值
InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);
Microsoft .Office .Interop .Owc11.ChDataLabels dl=InsertChart.SeriesCollection[0].DataLabelsCollection.Add();
dl.HasValue = true;
}
//输出文件.
string strAbsolutePath = (Server.MapPath(".")) + "//ShowData.gif";
laySpace.ExportPicture(strAbsolutePath, "GIF", 800,600); //创建GIF文件的相对路径.
string strRelativePath = "./ShowData.gif"; //把图片添加到placeholder中,并在页面上显示
string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));
}
}
解决方案 »
- 请问哪里有TlbImp.exe下载呀
- 用.NET做网站,头文件 是不是用 用户控件给做成公共文件?
- 验证码问题
- 有那位高手用C#写过发短信软件,有原代码更好。如果有这个项目的给我一份谢谢。我的邮箱[email protected]
- 为什么生成缩略图后缩略图的文件头会为变?而用其它软件直接编辑缩小文件头不会变?
- 简单问题,请指教。
- 如何获取TOOLBAR控件中的子控件
- uploadify上传文件控件后台如何获取它的文件大小和名字
- 请教datagrid排序问题!
- 如何用vml动态的创建带有文本的矩形图像(急!急!急!急!在线等待)
- 请教正则表达式!高手进
- 100分求教Oracle 组合查询性能提升
生成的折线图是这样的,不显示折线。
http://hi.baidu.com/bingyan719/album/item/f26e62127c8ab9f26438db8c.html#
希望各位指教,多谢了