ASP.NET 饼图仅显示 YValueMembers
ASP.NET Pie chart only displaying YValueMembers
我正在尝试创建一个图表来显示选中和未选中答案的百分比 booklets.But 饼图仅显示未选中的值,即 YValueMember。如何解决?
protected void DropDown_Subjects_SelectedIndexChanged(object sender, EventArgs e)
{
Chart4.Visible = true;
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
SqlCommand cmd = new SqlCommand("select checked_percent, unchecked_percent From(select COUNT(*) * 100.0 / (select count(*)from[newexam2017].[dbo].[newexam2017] where sub_code = '" + DropDown_Subjects.SelectedValue + "') as checked_percent from[newexam2017].[dbo].[newexam2017] where CheckBy is not null and sub_code = '" + DropDown_Subjects.SelectedValue + "' )checked,(select COUNT(*) * 100.0 / (select count(*)from[newexam2017].[dbo].[newexam2017] where sub_code = '" + DropDown_Subjects.SelectedValue + "')as unchecked_percent from[newexam2017].[dbo].[newexam2017] where CheckBy is null and sub_code = '" + DropDown_Subjects.SelectedValue + "')unchecked", connection);
connection.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable ChartData = ds.Tables[0];
Chart4.DataSource = ChartData;
Chart4.Series[0].Points.DataBind(ChartData.DefaultView, "checked_percent", "unchecked_percent", "");
for (int i = 0; i < Chart4.Series[0].Points.Count; i++)
Chart4.Series[0].Points[i].Label = string.Format("{0:0.00}%", ChartData.Rows[i]["checked_percent"], "{0:0.00}%", ChartData.Rows[i]["unchecked_percent"]);
connection.Close();
}
asp代码:
<asp:Chart ID="Chart4" runat="server" BackColor="DarkSlateBlue" BackGradientStyle="LeftRight"
BorderlineWidth="0" Height="440px" Palette="SeaGreen" PaletteCustomColors="24, 0, 0"
Width="560px" BorderlineColor="128, 128, 255" OnLoad="Chart4_Load">
<Titles>
<asp:Title Name="DefaultTitle" Font="Trebuchet MS, 15pt, style=Bold"
Text = "Overall Scoring Progress" />
</Titles>
<%-- <Legends>
<asp:Legend Name="DefaultLegend" Enabled="True" Docking="Top" />
</Legends>--%>
<Series>
<asp:Series Name="Series1" IsValueShownAsLabel="true" YValuesPerPoint="10" ChartType="Pie"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea4" >
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
我想要的:
我得到的:
在饼图中,checked_percent
和 unchecked_percent
都必须是 Y 值。像这样:
protected void Chart4_Load(object sender, EventArgs e)
{
Chart4.Series[0].Points.Add(new DataPoint(0, (double)ChartData.Rows[0]["unchecked_percent"]));
Chart4.Series[0].Points.Add(new DataPoint(1, (double)ChartData.Rows[0]["checked_percent"]));
}
编辑: 包括自定义标签:
protected void Chart4_Load(object sender, EventArgs e)
{
DataPoint dp = new DataPoint(0, (double)ChartData.Rows[0]["unchecked_percent"]);
dp.Label = string.Format("unchecked\n{0:0.00}%", ChartData.Rows[0]["unchecked_percent"]);
Chart4.Series[0].Points.Add(dp);
dp = new DataPoint(1, (double)ChartData.Rows[0]["checked_percent"]);
dp.Label = string.Format("checked\n{0:0.00}%", ChartData.Rows[0]["checked_percent"]);
Chart4.Series[0].Points.Add(dp);
}
我正在尝试创建一个图表来显示选中和未选中答案的百分比 booklets.But 饼图仅显示未选中的值,即 YValueMember。如何解决?
protected void DropDown_Subjects_SelectedIndexChanged(object sender, EventArgs e)
{
Chart4.Visible = true;
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
SqlCommand cmd = new SqlCommand("select checked_percent, unchecked_percent From(select COUNT(*) * 100.0 / (select count(*)from[newexam2017].[dbo].[newexam2017] where sub_code = '" + DropDown_Subjects.SelectedValue + "') as checked_percent from[newexam2017].[dbo].[newexam2017] where CheckBy is not null and sub_code = '" + DropDown_Subjects.SelectedValue + "' )checked,(select COUNT(*) * 100.0 / (select count(*)from[newexam2017].[dbo].[newexam2017] where sub_code = '" + DropDown_Subjects.SelectedValue + "')as unchecked_percent from[newexam2017].[dbo].[newexam2017] where CheckBy is null and sub_code = '" + DropDown_Subjects.SelectedValue + "')unchecked", connection);
connection.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable ChartData = ds.Tables[0];
Chart4.DataSource = ChartData;
Chart4.Series[0].Points.DataBind(ChartData.DefaultView, "checked_percent", "unchecked_percent", "");
for (int i = 0; i < Chart4.Series[0].Points.Count; i++)
Chart4.Series[0].Points[i].Label = string.Format("{0:0.00}%", ChartData.Rows[i]["checked_percent"], "{0:0.00}%", ChartData.Rows[i]["unchecked_percent"]);
connection.Close();
}
asp代码:
<asp:Chart ID="Chart4" runat="server" BackColor="DarkSlateBlue" BackGradientStyle="LeftRight"
BorderlineWidth="0" Height="440px" Palette="SeaGreen" PaletteCustomColors="24, 0, 0"
Width="560px" BorderlineColor="128, 128, 255" OnLoad="Chart4_Load">
<Titles>
<asp:Title Name="DefaultTitle" Font="Trebuchet MS, 15pt, style=Bold"
Text = "Overall Scoring Progress" />
</Titles>
<%-- <Legends>
<asp:Legend Name="DefaultLegend" Enabled="True" Docking="Top" />
</Legends>--%>
<Series>
<asp:Series Name="Series1" IsValueShownAsLabel="true" YValuesPerPoint="10" ChartType="Pie"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea4" >
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
我想要的:
我得到的:
在饼图中,checked_percent
和 unchecked_percent
都必须是 Y 值。像这样:
protected void Chart4_Load(object sender, EventArgs e)
{
Chart4.Series[0].Points.Add(new DataPoint(0, (double)ChartData.Rows[0]["unchecked_percent"]));
Chart4.Series[0].Points.Add(new DataPoint(1, (double)ChartData.Rows[0]["checked_percent"]));
}
编辑: 包括自定义标签:
protected void Chart4_Load(object sender, EventArgs e)
{
DataPoint dp = new DataPoint(0, (double)ChartData.Rows[0]["unchecked_percent"]);
dp.Label = string.Format("unchecked\n{0:0.00}%", ChartData.Rows[0]["unchecked_percent"]);
Chart4.Series[0].Points.Add(dp);
dp = new DataPoint(1, (double)ChartData.Rows[0]["checked_percent"]);
dp.Label = string.Format("checked\n{0:0.00}%", ChartData.Rows[0]["checked_percent"]);
Chart4.Series[0].Points.Add(dp);
}