我正在使用C#语言处理Asp.Net图表。我向用户提供选项,他从数据库中选择字段并形成图表,还可以选择使用名称保存这些设置当用户想要查看他的保存设置时,他只需点击并绘制图形,然后制作一个智能列表。但是当用户点击他的保存设置图表的名称不正确并且没有正确显示轴时,我的代码如下:
protected void btnShowSmartList_Click(object sender, EventArgs e)
{
string _SmartList ;
ds = GetDataSet("SELECT [Sql_Query] FROM [DWH_SmartList] WHERE sys_SmartList_No=" + ddSmartQueryList.SelectedValue) ;
_SmartList = Convert.ToString(ds.Tables[0].Rows[0]["Sql_Query"]);
ds.Tables[0].Dispose();
ds = new DataSet();
ds = GetDataSet(_SmartList);
Chart1.DataSource = ds;
Chart1.Legends.Add("Inspection_Date").Title = "Inspection_Date";
Chart1.ChartAreas["ChartArea1"].AxisX.Title = Dd_List.SelectedValue;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.MinorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.MinorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MinorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MinorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.Title = Dd_ListY.SelectedValue;
Chart1.Series["Series1"].XValueMember = Dd_List.SelectedValue;
Chart1.Series["Series1"].YValueMembers = Dd_ListY.SelectedValue;
Chart1.Series["Series1"].LegendText = Dd_ListY.SelectedValue;
this.GridFormatting();
Chart1.DataBind();
//Chart1.BackColor = System.Drawing.Color.White;
// this.Chart1.ChartAreas["ChartArea1"].AxisY.IsStartedFromZero = false;
GridView1.SelectedIndex = 0;
GridView1.DataSource = ds;
GridView1.DataBind();
}
网格运行良好,但图形不是
答案 0 :(得分:0)
我自己先解决了这个问题,然后用这段代码保存了所有Axis数据库中的值
{
string connectionString = ConfigurationManager.ConnectionStrings["KTConnectionString"].ToString();
cmd.Connection = con;
KTDataContext dataContext = new KTDataContext(connectionString);
DWH_SmartList tbip = new DWH_SmartList();
tbip.Sql_Query = txtQuery.Text;
tbip.Y_Axis = Dd_ListY.SelectedValue;
tbip.Y1_Axis = Dd_ListYSec.SelectedValue;
tbip.Y2_Axis = Dd_List3.SelectedValue;
tbip.Y3_Axis = Dd_List4.SelectedValue;
tbip.Y4_Axis = Dd_List5.SelectedValue;
tbip.SmartList_Description = txt_SmartList.Text;
tbip.User_Code = Convert.ToInt32( Session["UserCode"]);
dataContext.DWH_SmartLists.InsertOnSubmit(tbip);
dataContext.SubmitChanges();
}
然后我通过这段代码检索它: {
string _SmartList,_yaxis,_y1axis,_y2axis,_y3axis,_y4axis,_y5axis;
ds = GetDataSet("SELECT [Sql_Query],[Y_Axis],[Y1_Axis],[Y2_Axis],[Y3_Axis],[Y4_Axis],[Y5_Axis] FROM [DWH_SmartList] WHERE sys_SmartList_No=" + ddSmartQueryList.SelectedValue) ;
_SmartList = Convert.ToString(ds.Tables[0].Rows[0]["Sql_Query"]);
_yaxis = Convert.ToString(ds.Tables[0].Rows[0]["Y_Axis"]);
_y1axis= Convert.ToString(ds.Tables[0].Rows[0]["Y1_Axis"]);
_y2axis = Convert.ToString(ds.Tables[0].Rows[0]["Y2_Axis"]);
_y3axis = Convert.ToString(ds.Tables[0].Rows[0]["Y4_Axis"]);
_y4axis = Convert.ToString(ds.Tables[0].Rows[0]["Y4_Axis"]);
_y5axis = Convert.ToString(ds.Tables[0].Rows[0]["Y5_Axis"]);
Dd_ListY.SelectedValue = _yaxis ;
Dd_ListYSec.SelectedValue = _y1axis;
Dd_List3.SelectedValue = _y2axis;
Dd_List4.SelectedValue = _y3axis;
Dd_List5.SelectedValue = _y4axis;
ds.Tables[0].Dispose();
ds = new DataSet();
ds = GetDataSet(_SmartList);
Chart1.DataSource = ds;
Chart1.Legends.Add("Inspection_Date").Title = "Inspection_Date";
Chart1.ChartAreas["ChartArea1"].AxisX.Title = Dd_List.SelectedValue;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.MinorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.MinorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MinorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MinorTickMark.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.Title = Dd_ListY.SelectedValue;
Chart1.Series["Series1"].XValueMember = Dd_List.SelectedValue;
Chart1.Series["Series1"].YValueMembers = Dd_ListY.SelectedValue;
Chart1.Series["Series1"].LegendText = Dd_ListY.SelectedValue;
this.GridFormatting();
Chart1.DataBind();
//Chart1.BackColor = System.Drawing.Color.White;
// this.Chart1.ChartAreas["ChartArea1"].AxisY.IsStartedFromZero = false;
GridView1.SelectedIndex = 0;
GridView1.DataSource = ds;
GridView1.DataBind();
}
我的项目也完成了支持,并帮助stackoverflow专业人员和http://stackoverflow.com