转载:
http://www.cnblogs.com/muer/p/yaxle.html
代码:
public ActionResult ImportData(HttpPostedFileBase file) { Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; Cells cells = sheet.Cells; cells[0, 1].PutValue("Income"); cells[0, 2].PutValue("Expense"); cells[1, 0].PutValue("Company A"); cells[2, 0].PutValue("Company B"); cells[3, 0].PutValue("Company C"); cells[1, 1].PutValue(10000); cells[2, 1].PutValue(20000); cells[3, 1].PutValue(30000); cells[1, 2].PutValue(8000); cells[2, 2].PutValue(15000); cells[3, 2].PutValue(28000); int chartIndex = sheet.Charts.Add(ChartType.Column, 6, 6, 21, 15); Aspose.Cells.Charts.Chart chart = sheet.Charts[chartIndex]; //第一条柱子 chart.NSeries.Add("B2:B4", true); chart.NSeries.CategoryData = "A2:A4"; Series aSeries1 = chart.NSeries[0]; aSeries1.Name = "=B1"; chart.NSeries.IsColorVaried = true; //第二条柱子 chart.NSeries.Add("C2:C4", true); chart.NSeries.CategoryData = "A2:A4"; Series aSeries2 = chart.NSeries[1]; aSeries2.Name = "=C1"; //修改柱子颜色 aSeries2.Area.ForegroundColor = System.Drawing.Color.Green; //修改柱形图背景色 chart.PlotArea.Area.ForegroundColor = System.Drawing.Color.FromArgb(1, 152, 186, 180); //修改区域背景色 chart.ChartArea.Area.ForegroundColor = System.Drawing.Color.White; //显示数据表 chart.ShowDataTable = true; //显示分类条 chart.ShowLegend = true; chart.Title.Text = "Income Analysis"; workbook.Save(path); return null; }