好了,不罗嗦了 ,直接粘贴关键源码吧:
public void CreatePinReport()
{
//创建之前删除生成的文件
string deleteFileName = "stat.gif";//要删除的文件名称
try
{
string[] rootDirs = Directory.GetDirectories("http://images.cnblogs.com/"); //当前目录的子目录:
string[] rootFiles = Directory.GetFiles("http://images.cnblogs.com/"); //当前目录下的文件:
foreach (string s2 in rootFiles)
{
if (s2.Contains(deleteFileName))
{
Console.WriteLine(s2);
File.Delete(s2); //删除文件
}
}
}
catch (Exception)
{
}
//创建X坐标的值,表示月份
string[] month = GetNop_DictionaryWineType();
//创建Y坐标的值,表示销售额
List<double> list = new List<double>();
for (int i = 0; i < GetNop_DictionaryValueWineType().Length; i++)
{
//count = GetSumOrderByProductCategoryID(Convert.ToInt32(GetNop_DictionaryValueWineType()[i]));
list.Add(GetSumOrderByProductCategoryID(Convert.ToInt32(GetNop_DictionaryValueWineType()[i])));
}
double[] count = list.ToArray();
string strDataName = "";
string strData = "";
//创建图表空间
ChartSpace mychartSpace = new ChartSpace();
mychartSpace.Border.Color = "White";
//在图表空间内添加一个图表对象
ChChart mychart = mychartSpace.Charts.Add(0);
//设置每块饼的数据
for (int i = 0; i < count.Length; i++)
{
strDataName += month[i]+ "\t";
strData += count[i] + "\t";
}
//设置图表类型,本例使用饼
mychart.Type = ChartChartTypeEnum.chChartTypePie;
//设置图表的一些属性
//是否需要图例
mychart.HasLegend = true;
//是否需要主题
mychart.HasTitle = true;
//主题内容
mychart.Title.Caption = "饼状图测试";
mychart.Title.Font.Size = 10;
mychart.Title.Font.Bold = false;
mychart.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom;
mychart.Legend.Interior.Color = "f9f9f9";
mychart.Legend.Font.Size = 9;
mychart.Legend.Border.Color = "White";
//添加图表块
mychart.SeriesCollection.Add(0);
//设置图表块的属性
//分类属性
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories,
(int)ChartSpecialDataSourcesEnum.chDataLiteral, strDataName);
//值属性
mychart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues,
(int)ChartSpecialDataSourcesEnum.chDataLiteral, strData);
for (int j = 0; j < mychart.SeriesCollection[0].Points.Count; j++)
{
mychart.SeriesCollection[0].Points[j].Border.Color = "White";
}
//显示百分比
ChDataLabels mytb = mychart.SeriesCollection[0].DataLabelsCollection.Add();
mytb.HasPercentage = true;
//mytb.Border.Color = "White";
mytb.HasValue = true;
//生成图片
mychartSpace.ExportPicture(Server.MapPath("../images/") + @"stat.gif", "gif", 700, 400);
//加载图片
this.ig.ImageUrl = "http://images.cnblogs.com/stat.gif";
}
以下是代码显示效果图:
代码很简单,而且有详细的注释,希望大家多多指教..