我想生成一个条形图并动态显示它的详细信息。我试图显示带有四个值的条形图。但它没有用。我的代码如下。请帮帮我
public partial class chartDummy : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(@"ConnectionString");
cmd = new SqlCommand("Select Mains_Run_Hrs, DG_Run_Auto_Mode, Battery_Run_Hrs, Solar_Run_hrs from tbl_runtime_report", con);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
Chart1.DataSource = ds;
Chart1.Series[0].XValueMember = "Mains_Run_Hrs";
Chart1.Series[0].XValueMember = "DG_Run_Auto_Mode";
Chart1.Series[0].XValueMember = "Battery_Run_Hrs";
Chart1.Series[0].XValueMember = "Solar_Run_hrs";
Chart1.DataBind();
}
}
源:
<div>
<asp:Chart ID="Chart1" runat="server" CssClass="auto-style1" Width="558px">
<Series>
<asp:Series Name="Main Run Hrs"></asp:Series>
<asp:Series Name="DG Run Auto Mode"></asp:Series>
<asp:Series Name="Battery Run Hrs"></asp:Series>
<asp:Series Name="Solar Run Hrs"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
<Legends>
<asp:Legend Title="Solar Data"></asp:Legend>
</Legends>
</asp:Chart>
</div>
答案 0 :(得分:0)
下面给出的代码完美无缺。它根据db数据显示流程图。谢谢。
public partial class chartDummy : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(@"ConnectionString");
cmd = new SqlCommand("Select Mains_Run_Hrs, DG_Run_Auto_Mode, Battery_Run_Hrs, Solar_Run_hrs from tbl_runtime_report", con);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
Chart1.DataSource = ds;
Chart1.Series[0].YValueMembers = "Mains_Run_Hrs";
Chart1.Series[0].XValueMember = "DG_Run_Auto_Mode";
Chart1.Series[0].XValueMember = "Battery_Run_Hrs";
Chart1.Series[0].XValueMember = "Solar_Run_hrs";
Chart1.DataBind();
}
}