ASP.NET饼图仅显示YValueMembers [英] ASP.NET Pie chart only displaying YValueMembers

查看:96
本文介绍了ASP.NET饼图仅显示YValueMembers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个图表以显示已选中和未选中的答案手册的百分比,但是饼图仅显示未选中的值,即YValueMember.该如何解决?

I am trying to create a chart to display the percentage of checked and unchecked answer booklets.But the pie chart is only showing the unchecked value which is the YValueMember. How to resolve this?

 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_percentunchecked_percent都必须是Y值.像这样:

In a pie chart, both, checked_percent and unchecked_percent, must be Y-values. Like this:

 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);
}

这篇关于ASP.NET饼图仅显示YValueMembers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆