【问题标题】:MS Pie Chart with both X,Y Value on graph using asp.net web forms使用 asp.net 网络表单在图表上同时显示 X、Y 值的 MS 饼图
【发布时间】:2012-02-22 12:36:35
【问题描述】:

我正在开发 asp.net Web 应用程序,我需要在其中以饼图的形式显示数据。图表应同时显示 X 值和 Y 值。在下图中,您可以看到我只能在一年内显示 cmets 的总数,但我还想在每种颜色旁边显示年份。我尝试了不同的东西,但到目前为止我没有成功。

我也是图相关的post code

<asp:Chart ID="crtYearWise" runat="server" Height="260px" Width="460px">
    <Titles>
        <asp:Title Name="Title1" Text="Year Wise"
            Alignment="TopCenter" Font="Verdana, 12pt">
        </asp:Title>
    </Titles>
    <Series>
        <asp:Series Name="Series1" CustomProperties="DrawingStyle=Pie,
            PieDrawingStyle=Concave, MaxPixelPointWidth=20" ShadowOffset="1"
            ChartType="Pie" IsValueShownAsLabel="True" >
        </asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="True" AlignmentOrientation="All">
            <Area3DStyle Enable3D="true" />
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>  

代码背后

String strSql2 = "SELECT Count(comPostDate) AS 'comTOTAL',  DATEPART(yyyy, comPostDate) AS 'whichYear' ";
strSql2 += " FROM Comments  Group by  DATEPART(yyyy, comPostDate), DATEPART(yyyy, comPostDate) ";
DataSet ds2 = DataProvider.Connect_Select(strSql2);

DataTable dt2 = ds2.Tables[0];
crtYearWise.DataSource = dt2;
crtYearWise.Series["Series1"].XValueMember = "whichYear";
crtYearWise.Series["Series1"].YValueMembers = "comTOTAL";
//crtYearWise.Series["Series1"]["PieLabelStyle"] = "Outside";
crtYearWise.DataBind();

如果有人可以指导我,我将不胜感激。

答案:Finally Managed 得到了它

crtYearWise.Series["Series1"].Label = "年份 : #VALX , #VALY";

【问题讨论】:

    标签: c# webforms mschart


    【解决方案1】:

    This blog post 有一些有用的信息。

    例如,您可以通过设置:

    <asp:Series Label="#VALX: #VALY" ...
    

    您还可以格式化 X 和 Y 值,例如:

    <asp:Series Label="#VALX: #VALY{N0}"
    

    我必须说关于 Chart 控件的 MSDN 文档很差;例如,Chart overview 没有任何指向此类常见任务的“操作方法”主题的链接,最好的信息来源似乎是 MSDN 博客文章。

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      相关资源
      最近更新 更多