//创建饼状图表 Chart chart = sheet.Charts.Add(ExcelChartType.Pie); //设置图表的数据范围,使用的也是和前面单元格获取的Range对象 chart.DataRange = sheet.Range["B2:B5"]; chart.SeriesDataFromRange = false; //设置图表的位置 chart.LeftColumn = 1;//图表左边列 chart.TopRow = 6;//图表上部的行 chart.RightColumn = 6;//图表右边列 chart.BottomRow = 18;//图表底部行 //图表标题 chart.ChartTitle = "饼形图例子"; //设置字体 chart.ChartTitleArea.IsBold = true; chart.ChartTitleArea.Size = 12; //初始化图例 Spire.Xls.Charts.ChartSerie cs = chart.Series[0]; //图表的标签目录数据 cs.CategoryLabels = sheet.Range["A2:A5"]; //图表的主要值,也就是饼状图的数据 cs.Values = sheet.Range["B2:B5"];
//给Sheet对象添加一个图表对象,可以直接添加类型,也可以单独用ChartType赋值来添加
Chart chart = sheet.Charts.Add();
chart.ChartType = ExcelChartType.Line3D;
//设置图表的数据范围
chart.DataRange = sheet.Range["A1:E5"];
//设置图表的保存位置,这个基本都差不多
chart.LeftColumn = 1;
chart.TopRow = 6;
chart.RightColumn = 7;
chart.BottomRow = 22;
//图表标题
chart.ChartTitle = "折线图例子";
//设置字体加粗和大小
chart.ChartTitleArea.IsBold = true;
chart.ChartTitleArea.Size = 12;
//设置横坐标的标题
chart.PrimaryCategoryAxis.Title = "月份";
chart.PrimaryCategoryAxis.Font.IsBold = true;
chart.PrimaryCategoryAxis.TitleArea.IsBold = true;
//设置纵坐标,也就是值 的标题
chart.PrimaryValueAxis.Title = "销售额";
chart.PrimaryValueAxis.HasMajorGridLines = false;
chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90;
chart.PrimaryValueAxis.MinValue = 1000;
chart.PrimaryValueAxis.TitleArea.IsBold = true;
//循环绘制不同国家的销售额折线图,有多个系列
foreach (Spire.Xls.Charts.ChartSerie cs in chart.Series)
{
cs.Format.Options.IsVaryColor = true;
cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
}
Workbook workbook = new Workbook();
workbook.LoadFromFile("chart.xlsx", ExcelVersion.Version2010);
Worksheet sheet=workbook.Worksheets[0];
Image[] imgs = workbook.SaveChartAsImage(sheet);
for (int i = 0; i < imgs.Length; i++)
{
imgs[i].Save(string.Format("img-{0}.png", i), ImageFormat.Png);
}
chart.Width = 400; chart.Height = 250;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有