用ChartSpace和Chchart类画巡视轨迹图问题,当显示一条轨迹时能正常显示,两条同时显示时,第二调的轨迹位置有点偏,猜测是受第一条影响,怎么让两条都显示正常呢?
前台: <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:Button ID="Button1" runat="server" Text="查询" Width="70px" Font-Names="宋体" Font-Size="9pt"
OnClick="Button1_Click" CssClass="blueButtonCss" />
后台:
public void SetXsgj(string jgbm, string qjbm, string rq)//根据条件显示相应的轨迹
{
try
{
#region 显示相应的轨迹
//侯庆东 2008-06-25 //周继光 2008-08-12 //修改多个用户同时查看时图片显示问题
string connectstring = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
//读取标准位置数据 旧pda链接字符串-- by css 09-11-28
//string sql = "select y_gwjx_bzwz.zzjd,y_gwjx_bzwz.zzwd from j_gdgy_zzkjxx,y_gwjx_bzwz where j_gdgy_zzkjxx.zzbm=y_gwjx_bzwz.zzbm and y_gwjx_bzwz.zzjd>0 and y_gwjx_bzwz.zzwd>0 and jgbm='" + jgbm + "' and qjzcbm='" + qjbm + "' ORDER by zzjd,zzwd ";
string sql = "select j_gdgy_zzkjxx.zzjd,j_gdgy_zzkjxx.zzwd from j_gdgy_zzkjxx where j_gdgy_zzkjxx.zzjd>0 and j_gdgy_zzkjxx.zzwd>0 and jgbm='" + jgbm + "' and qjzcbm='" + qjbm + "' ORDER by zzjd,zzwd ";//读取标准位置数据
string sql2 = "select zzjd,zzwd from y_gwjx_xsgj where jgbm='" + jgbm + "' and qjzcbm='" + qjbm + "' and to_char(xssj,'yyyy-mm-dd') ='" + rq + "' ORDER BY zzjd,zzwd";//读取巡视轨迹数据
OracleConnection myConn = new OracleConnection(connectstring);
myConn.Open();
OracleDataAdapter Da = new OracleDataAdapter(sql, myConn);
DataSet ds = new DataSet();
Da.Fill(ds);
//Response.Write(ds.Tables[0].Rows.Count);
OracleDataAdapter da2 = new OracleDataAdapter(sql2, myConn);
DataSet ds2 = new DataSet();
da2.Fill(ds2);
if (ds.Tables[0].Rows.Count < 1 || ds2.Tables[0].Rows.Count < 1)
{
Engine.AjaxPop(UpdatePanel2, "没有巡视数据!");
}
else
{
string[] jd = new string[ds.Tables[0].Rows.Count];
string[] wd = new string[ds.Tables[0].Rows.Count];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
jd[i] = (Math.Round((Convert.ToDouble(ds.Tables[0].Rows[i][0])),6)).ToString();
wd[i] = (Math.Round((Convert.ToDouble(ds.Tables[0].Rows[i][1])), 6)).ToString();
}
//为x轴指定特定字符串,以便显示数据
string strXdata = String.Empty;
foreach (string strDatax in jd)
{
strXdata += strDatax + "\t";
}
string strYdata = String.Empty;
//为y轴指定特定的字符串,以便与x轴相对应
foreach (string strValue in wd)
{
strYdata += strValue + "\t";
}
string[] jd2 = new string[ds2.Tables[0].Rows.Count];
string[] wd2 = new string[ds2.Tables[0].Rows.Count];
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
jd2[i] = (Math.Round((Convert.ToDouble(ds2.Tables[0].Rows[i][0])), 6)).ToString();
wd2[i] = (Math.Round((Convert.ToDouble(ds2.Tables[0].Rows[i][1])), 6)).ToString();
}
//为x轴指定特定字符串,以便显示数据
string strXdata2 = String.Empty;
foreach (string strData2 in jd2)
{
strXdata2 += strData2 + "\t";
}
string strYdata2 = String.Empty;
//为y轴指定特定的字符串,以便与x轴相对应
foreach (string strValue2 in wd2)
{
strYdata2 += strValue2 + "\t";
}
//创建图表空间
ChartSpace mychartSpace = new ChartSpace();
object constants = mychartSpace.Constants;
//在图表空间内添加一个图表对象
ChChart mychart = mychartSpace.Charts.Add(0);
mychart.Border.Color = "White";
//ChChart mychart2 = mychartSpace.Charts.Add(1);
//设置每块饼的数据
//设置图表类型,本例使用柱形
mychart.Type = ChartChartTypeEnum.chChartTypeLine;
//设置图表的一些属性
//是否需要图例
mychart.HasLegend = true;
//是否需要主题
mychart.HasTitle = true;
//主题内容
mychart.Title.Caption = "巡视轨迹";
//添加图表块
mychart.SeriesCollection.Add(0);
mychart.SeriesCollection.Add(1);
//设置图表块的属性
mychart.Axes[0].HasTitle = true;
mychart.Axes[0].Title.Caption = "纬度";
mychart.Axes[0].HasMajorGridlines = false;
mychart.Axes[0].HasAutoMajorUnit = false;
mychart.Axes[0].HasTickLabels = false;
//图列放在底部
mychart.Legend.Position = OWC11.ChartLegendPositionEnum.chLegendPositionBottom;
//mychart.ChartDepth = 0;
//mychart.Interior.BackColor = "red";
mychart.Axes[1].HasTitle = true;
mychart.Axes[1].Title.Caption = "经度";
mychart.Axes[1].HasMajorGridlines = false;
mychart.Axes[1].HasTickLabels = false;
mychart.SeriesCollection[0].Caption = "巡视轨迹";
mychart.SeriesCollection[0].Marker.Size = 10; //"red";//255;
//mychart.SeriesCollection[0].Line.Color ="#ff0000";//255;
mychart.SeriesCollection[0].Line.Color = OWC11.ChartColorIndexEnum.chColorNone;
mychart.SeriesCollection[0].Marker.Style = ChartMarkerStyleEnum.chMarkerStyleCircle;
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "巡视轨迹");
//值属性
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);
//分类属性
mychart.SeriesCollection[1].Caption = "标准轨迹";
mychart.SeriesCollection[1].Marker.Size = 10; //"red";//255;
//mychart.SeriesCollection[0].Line.Color ="#ff0000";//255;
mychart.SeriesCollection[1].Line.Color = OWC11.ChartColorIndexEnum.chColorNone;
mychart.SeriesCollection[1].Marker.Style = ChartMarkerStyleEnum.chMarkerStyleX;
mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, "标准轨迹");
//值属性
mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimCategories, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata2);
mychart.SeriesCollection[1].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata2);
string strAbsolutePath = (Server.MapPath(".")) + "\\" + "XsgjPhoto\\" + DropRq.SelectedItem.Text.Replace("-", "") + ".gif";//临时存放图片的名称
string aa = strAbsolutePath;
if (aa.Length > 0)
{
File.Delete(aa);
}
mychartSpace.ExportPicture(strAbsolutePath, "GIF", 950, 550);
//创建GIF文件的相对路径.
string strRelativePath = "./" + "XsgjPhoto/" + DropRq.SelectedItem.Text.Replace("-", "") + ".gif";
//把图片添加到placeholder中,并在页面上显示
string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));
}
#endregion
}
catch
{
}
}