您的位置:首页 > 编程语言 > ASP

asp.net chart美化+绑定数据--饼图

2015-11-30 17:25 375 查看
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="0" />
<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[0].BackColor = Color.Wheat;
// add and format the title
Chart3.Titles.Add("标题");
Chart3.Titles[0].Font = new Font("Utopia", 14, FontStyle.Bold);

Chart3.Series.Add(new Series("Pie")
{
ChartType = SeriesChartType.Pie,
ShadowOffset = 2
});
Chart3.Series[0].Label = "#VALX \n\n #PERCENT{P}";//显示百分比和说明
Chart3.Series[0].LegendText = "#VALX";
double[] yValues = { 23, 12, 26, 39, };
string[] xValues = { "优秀", "不及格", "良好", "及格" };
//饼状图的标签方位
Chart3.Series[0]["PieLabelStyle"] = "Outside";
Chart3.Series[0]["PieLineColor"] = "Black";
Chart3.Series[0].Points.DataBindXY(xValues, yValues);

//每个部分开花
foreach (DataPoint point in Chart3.Series[0].Points)
{
point["Exploded"] = "true";
}
SaveChartToImg(Chart3, "4");


预览图如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: