// Set the GraphPane title
graphPane.Title.FontSpec.IsItalic = true;
graphPane.Title.FontSpec.Size = 24f;
graphPane.Title.FontSpec.Family = "Times New Roman";
// Fill the pane background with a color gradient
graphPane.Fill = new Fill(Color.White, Color.Goldenrod, 45.0f);
// No fill for the chart background
graphPane.Chart.Fill.Type = FillType.None;
// Set the legend to an arbitrary location
graphPane.Legend.Position = LegendPos.Float;
graphPane.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction,
AlignH.Right, AlignV.Top); //设置饼图显示位置
graphPane.Legend.FontSpec.Size = 10f; //设置字体大小
graphPane.Legend.IsHStack = false;
TextObj text = new TextObj("", 0.18F, 0.40F, CoordType.ChartFraction);
graphPane.Fill = new Fill(Color.White, Color.Silver, 45.0f);
double y = 0.00;
string name1 = "";
for (int i = 0; i < dtyear.Rows.Count; i++)
{
y = Convert.ToDouble(string.IsNullOrEmpty(dtyear.Rows[i]["金额"].ToString()) == true ? "0" : dtyear.Rows[i]["金额"].ToString());
name1 = dtyear.Rows[i]["日期"].ToString() + "," + dtyear.Rows[i]["金额"].ToString();
graphPane.AddPieSlice(y, GetRandomColor(), Color.White, 45f, 0, name1);
}
dtyear.Rows.Add(new object[] { "总额", huikuan.ToString() });
GridView1.DataSource = dtyear; //如果要求下面显示列表数据时,给GridView1绑定数据
GridView1.DataBind();
dtyear = null;
CurveList curves = graphPane.CurveList;
double total = 0;
for (int x = 0; x < curves.Count; x++)
total += ((PieItem)curves[x]).Value;
// Make a text label to highlight the total value
text.Text = "总额" + huikuan.ToString();
text.Location.AlignH = AlignH.Center;
text.Location.AlignV = AlignV.Bottom;
text.FontSpec.Border.IsVisible = false;
text.FontSpec.Fill = new Fill(Color.White, Color.FromArgb(255, 100, 100), 45F);
text.FontSpec.StringAlignment = StringAlignment.Center;
graphPane.GraphObjList.Add(text);
// Create a drop shadow for the total value text item
TextObj text2 = new TextObj(text);
text2.FontSpec.Fill = new Fill(Color.Black);
text2.Location.X += 0.008f;
text2.Location.Y += 0.01f;
graphPane.GraphObjList.Add(text2);
graphPane.AxisChange(grap);
}
3、创建随机颜色,设置饼图大小
// 创建随机颜色
private Color GetRandomColor()
{
Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
System.Threading.Thread.Sleep(RandomNum_First.Next(150));
Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
System.Threading.Thread.Sleep(RandomNum_Sencond.Next(150));
Random RandomNum_3 = new Random((int)DateTime.Now.Ticks);