【发布时间】:2017-07-13 10:39:30
【问题描述】:
我正在尝试创建一个图表来显示已选中和未选中的答案手册的百分比。但饼图仅显示未选中的值,即 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>
我想要什么:
我得到了什么:
【问题讨论】:
-
你在使用 Highcharts 吗?如果是,那么您似乎没有使用Highcharts .NET,您可以考虑使用它,因为这是 Highcharts 支持的与 .NET 环境集成的解决方案。
-
饼图每个点只能显示一个 Y 值,并且只包含一个系列。看看HERE;。或者也许您应该更好地指定您想要的最终结果。图片总是有用的。
-
您还可以按照我在HERE 的说明创建自定义标签。请注意不要创建“误导性”图表,因为在这种情况下您已经在使用百分比。
-
请检查上面的编辑。
-
对不起,我之前没有看到你的评论。一般来说,如果您想确保特定用户看到它,您必须添加 @somespecificusername。
标签: c# asp.net .net charts mschart