asp.net chart之饼图
开发环境VS2010 chart控件是vs自带控件
前台:
<asp:Chart ID="Chart3" runat="server" Width="900px">
<Legends>
<asp:Legend BackColor="Transparent" Alignment="Center" Font="Trebuchet MS, 8.25pt, style=Bold"
IsTextAutoFit="False" Name="Default" LegendStyle="Column">
</asp:Legend>
</Legends>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<Area3DStyle Rotation="" />
<AxisY LineColor="64, 64, 64, 64">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
<MajorGrid LineColor="64, 64, 64, 64" />
</AxisY>
<AxisX LineColor="64, 64, 64, 64">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
<MajorGrid LineColor="64, 64, 64, 64" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
后台(部分有注释):
Chart3.BackColor = Color.Moccasin;
Chart3.BackGradientStyle = GradientStyle.DiagonalRight;
Chart3.BorderlineDashStyle = ChartDashStyle.Solid;
Chart3.BorderlineColor = Color.Gray;
Chart3.BorderSkin.SkinStyle = BorderSkinStyle.Emboss; // forma the chart area
Chart3.ChartAreas[].BackColor = Color.Wheat;
// add and format the title
Chart3.Titles.Add("标题");
Chart3.Titles[].Font = new Font("Utopia", , FontStyle.Bold); Chart3.Series.Add(new Series("Pie")
{
ChartType = SeriesChartType.Pie,
ShadowOffset =
});
Chart3.Series[].Label = "#VALX \n\n #PERCENT{P}";//显示百分比和说明
Chart3.Series[].LegendText = "#VALX";
double[] yValues = { , , , , };
string[] xValues = { "优秀", "不及格", "良好", "及格" };
//饼状图的标签方位
Chart3.Series[]["PieLabelStyle"] = "Outside";
Chart3.Series[]["PieLineColor"] = "Black";
Chart3.Series[].Points.DataBindXY(xValues, yValues); //每个部分开花
foreach (DataPoint point in Chart3.Series[].Points)
{
point["Exploded"] = "true";
}
SaveChartToImg(Chart3, "");
预览图如下: