我正在开发asp.net Web应用程序,我需要在饼图中显示数据。图表应显示X值和Y值。在下图中,您可以看到我只能在一年的评论中显示总数,但我还想在每种颜色旁边显示年份。我尝试了不同的东西,但到目前为止我没有成功。
我也发布了与图表相关的代码
<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();
如果有人能指导我,我将不胜感激。
回答:最后管理得到了
crtYearWise.Series [“Series1”]。Label =“Year:#VALX,#VALY”;
答案 0 :(得分:2)
This blog post有一些有用的信息。
例如,您可以通过设置:
来完成此操作<asp:Series Label="#VALX: #VALY" ...
您还可以格式化X和Y值,例如:
<asp:Series Label="#VALX: #VALY{N0}"
我必须说Chart控件上的MSDN文档很差;例如,Chart overview没有指向&#34;操作方法&#34;像这样的常见任务的主题,以及最好的信息来源似乎是MSDN博客文章。
答案 1 :(得分:1)