使用Aspose.Cells 设置chart的y坐标轴显示值
目的:设置chart的y坐标轴显示值
用aspose.cell生成的chart生成的Y轴是默认生成的,自己要定义y轴坐标值
1.把数据源写到excel里面,list里面
2.y轴坐标自己定义
第一种:默认设置:chart里面会自己定义y轴坐标
第二种:y周坐标以对数显示 chart.ValueAxis.IsLogarithmic = true; 以10 100 1000格式显示
第三种:只设置间隔值 chart.ValueAxis.MajorUnit =20000;,会自动获取y轴的最大值与最小值
第四种:设置y轴的最大值与最小值,设置间隔值
//设置y坐标轴的厚度
chart.ValueAxis.AxisLine.Weight = WeightType.WideLine;
chart.ValueAxis.Title.Text = "y轴坐标";
chart.ValueAxis.MajorUnit =20000;//设置y轴的显示值间隔
chart.ValueAxis.MaxValue = 200000;//设置y轴开始最大值
chart.ValueAxis.MinValue = 0;//设置y轴的最小值
3.设置右边坐标轴是不是显示
//设置右边坐标轴显示
chart.SecondValueAxis.IsVisible = true;
//设置y坐标轴间隔值字大小
chart.SecondValueAxis.TickLabels.Font.Size = 12;
chart.SecondValueAxis.Title.Text = "y轴坐标2";
导出效果:
//设置y坐标轴的厚度
chart.ValueAxis.AxisLine.Weight = WeightType.WideLine;
chart.ValueAxis.Title.Text = "y轴坐标";
chart.ValueAxis.MajorUnit =20000;//设置y轴的显示值间隔
chart.ValueAxis.MaxValue = 200000;//设置y轴开始最大值
chart.ValueAxis.MinValue = 0;//设置y轴的最小值

第二种:y周坐标以对数显示 chart.ValueAxis.IsLogarithmic = true; 以10 100 1000格式显示

//设置y坐标轴的厚度
chart.ValueAxis.AxisLine.Weight = WeightType.WideLine;
chart.ValueAxis.Title.Text = "y轴坐标";
chart.ValueAxis.MajorUnit =20000;//设置y轴的显示值间隔
chart.ValueAxis.MaxValue = 80000;//设置y轴开始最大值
chart.ValueAxis.MinValue = 0;//设置y轴的最小值

入口函数
public ActionResult excels()
{
WorkbookDesigner designer = new WorkbookDesigner();
string path = Server.MapPath("/Templete/11111.xls");
designer.Workbook.Open(path);
Workbook workbook = designer.Workbook;
CreateStaticData(workbook);
CreateStaticReport(workbook);
designer.Process();
//将流文件写到客户端流的形式写到客户端,名称是_report.xls
designer.Save("_report.xls", SaveType.OpenInExcel, FileFormatType.Excel2003, System.Web.HttpContext.Current.Response);
Response.Flush();
Response.Close();
designer = null;
// Response.End();
return View("getexcel");
}
设置数据源
private void CreateStaticData(Workbook workbook)
{
//Initialize Cells object
Cells cells = workbook.Worksheets[0].Cells; //Put string into a cells of Column A
cells["A1"].PutValue("class");
cells["A2"].PutValue("红萝卜");
cells["A3"].PutValue("白萝卜");
cells["A4"].PutValue("青萝卜"); //Put a value into a Row 1
cells["B1"].PutValue(2002);
cells["C1"].PutValue(2003);
cells["D1"].PutValue(2004);
cells["E1"].PutValue(2005);
cells["F1"].PutValue(2006); //Put a value into a Row 2
cells["B2"].PutValue(40000);
cells["C2"].PutValue(45000);
cells["D2"].PutValue(50000);
cells["E2"].PutValue(55000);
cells["F2"].PutValue(70000); //Put a value into a Row 3
cells["B3"].PutValue(10000);
cells["C3"].PutValue(25000);
cells["D3"].PutValue(40000);
cells["E3"].PutValue(52000);
cells["F3"].PutValue(60000); //Put a value into a Row 4
cells["B4"].PutValue(5000);
cells["C4"].PutValue(15000);
cells["D4"].PutValue(35000);
cells["E4"].PutValue(30000);
cells["F4"].PutValue(20000);
}
设置chart y轴的显示值
private void CreateStaticReport(Workbook workbook)
{
//初始化 Worksheet
Worksheet sheet = workbook.Worksheets[0];
//设置 worksheet名称
sheet.Name = "Line";
//设置worksheet不显示
sheet.IsGridlinesVisible = false;
//根据数据源 创建 chart
int chartIndex = 0;
chartIndex = sheet.Charts.Add(ChartType.Line, 5, 1, 29, 15);
//初始化chart
Chart chart = sheet.Charts[chartIndex];
//设置竖线不显示
chart.CategoryAxis.MajorGridLines.IsVisible = false;
//设置Title样式
chart.Title.Text = "Sales By Class For Years";
chart.Title.TextFont.Color = Color.Black;
chart.Title.TextFont.IsBold = true;
chart.Title.TextFont.Size = 12;
//设置chart的数据源
chart.NSeries.Add("B2:F4", false);
chart.NSeries.CategoryData = "B1:F1";
//Set Nseries color varience to True
chart.NSeries.IsColorVaried = true;
//初始化 Cells
Cells cells = workbook.Worksheets[0].Cells;
//循环 cells
for (int i = 0; i < chart.NSeries.Count; i++)
{
//设置系列的名称
chart.NSeries[i].Name = cells[i + 1, 0].Value.ToString();
chart.NSeries[i].MarkerStyle = ChartMarkerType.Circle;
//设置系列的名称 Background 与ForeGround
chart.NSeries[i].MarkerBackgroundColor = Color.Yellow;
chart.NSeries[i].MarkerForegroundColor = Color.Gold;
//设置系列标记
chart.NSeries[i].MarkerSize = 10;
//设置Category的名称
chart.CategoryAxis.Title.Text = "Year(2002-2006)";
chart.CategoryAxis.Title.TextFont.Color = Color.Black;
chart.CategoryAxis.Title.TextFont.IsBold = true;
chart.CategoryAxis.Title.TextFont.Size = 10;
//设置图例的位置
chart.Legend.Position = LegendPositionType.Top;
} //设置y轴的样式
chart.ValueAxis.TickLabelPosition = TickLabelPositionType.NextToAxis;
chart.ValueAxis.TickLabels.Font.Color = Color.Gray;
chart.ValueAxis.AxisBetweenCategories = false;
//chart.ValueAxis.TickLabels.Font.Size = 13;
chart.ValueAxis.TickLabels.Font.IsBold = true;
//Y坐标轴对数间隔展示
// chart.ValueAxis.IsLogarithmic = true;
chart.ValueAxis.MajorGridLines.Color = Color.Red;
chart.ValueAxis.AxisLine.Color = Color.DarkGreen;
//设置y坐标轴的厚度
chart.ValueAxis.AxisLine.Weight = WeightType.WideLine;
chart.ValueAxis.Title.Text = "y轴坐标";
chart.ValueAxis.MajorUnit = 20000;//MajorUnit =2000;
chart.ValueAxis.MaxValue = 200000;
chart.ValueAxis.MinValue = 0;
//设置右边坐标轴显示
chart.SecondValueAxis.IsVisible = true;
//设置y坐标轴间隔值字大小
chart.SecondValueAxis.TickLabels.Font.Size = 12;
chart.SecondValueAxis.Title.Text = "y轴坐标2";
// chart.SecondValueAxis.MinorGridLines.IsVisible = true;
}
使用Aspose.Cells 设置chart的y坐标轴显示值的更多相关文章
- Aspose.Cells设置自动列宽(最佳列宽)及一些方法总结
/// <summary> /// 设置表页的列宽度自适应 /// </summary> /// <param name="sheet">wor ...
- Aspose.Cells 设置背景颜色
很多小伙伴设置背景颜色都不起作用,特别提醒需要加入下面一行: style.Pattern = BackgroundType.Solid; Aspose.Cells.Style style = null ...
- Aspose.Cells设置单元格格式
使用Aspose.Cells操作Excel时,填写的参数是这样的,显然要不得! 这需要像Excel中的“转换为数字”操作,强大的Aspose.Cells可轻松解决这个问题. //默认写法 worksh ...
- Excel Aspose.Cells 设置单元格格式 为数字
Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = workbook.Worksheets[]; //工作表 sheet.Cells ...
- 使用Aspose.Cells生成Excel的线型图表
目的: 1.根据模板里面的excel数据信息,动态创建line chart 2.linechart 的样式改为灰色 3.以流的形式写到客户端,不管客户端是否装excel,都可以导出到到客户端 4.使用 ...
- C#------Aspose.cells使用方法
转载: http://www.cnblogs.com/muer/p/yaxle.html 代码: public ActionResult ImportData(HttpPostedFileBase f ...
- [oldboy-django][2深入django]学生管理(Form)-- 编辑(设置input标签属性,设置input标签默认显示值,设置input的类型)
1 django 后台实现设置input标签属性,设置input标签默认显示值,设置input输入框类型 # Form生成html标签 a. 通过Form生成Input输入框,Form标签,以及sub ...
- 使用Aspose.Cells 根据模板生成excel里面的 line chart
目的: 1.根据模板里面的excel数据信息,动态创建line chart 2.linechart 的样式改为灰色 3.以流的形式写到客户端,不管客户端是否装excel,都可以导出到到客户端 4.使用 ...
- Asp.Net中应用Aspose.Cells输出报表到Excel 及样式设置
解决思路: 1.找个可用的Aspose.Cells(有钱还是买个正版吧,谁开发个东西也不容易): 2.在.Net方案中引用此Cells: 3.写个函数ToExcel(传递一个DataTable),可以 ...
随机推荐
- jQuery的XX如何实现?——4.类型检查
往期回顾: jQuery的XX如何实现?——1.框架 jQuery的XX如何实现?——2.show与链式调用 jQuery的XX如何实现?——3.data与cache机制 -------------- ...
- iOS 字典自动生成模型
在实际开发中,我们经常需要根据字典来建模型.每次都打那么一串代码,想想也是挺恶心的.可以自己给NSDictionary写一个分类,进行属性生成. NSDictionary+Property.h #im ...
- atitit.技术选型方法总结为什么java就是比.net有前途
atitit.技术选型方法总结为什么java就是比.net有前途 #----按照不同的需要有不铜的法... 一般有开发效率,稳定性上的需要.. 作者 老哇的爪子 Attilax 艾龙, EMAIL: ...
- iOS开发——高级技术&iCloud服务
iCloud服务 iCloud 是苹果提供的云端服务,用户可以将通讯录.备忘录.邮件.照片.音乐.视频等备份到云服务器并在各个苹果设备间直接进行共享而无需关心数据同步问题,甚至 即使你的设备丢失后在一 ...
- 每天一个linux命令(4):mkdir命令
linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录... 2.命令 ...
- Spring3.2.4集成quartz2.2.1定时任务(demo).
在JavaEE系统中,我们会经常用到定时任务,下面是我自己写的一个demo. 前面几篇quartz博客感觉看的还是难懂 于是重新整理下 源码地址:http://pan.baidu.com/s/1BXH ...
- 使用Reveal查看任意App的技巧
转:http://www.jianshu.com/p/4dc8f94ca27c 前言 Reveal(http://revealapp.com)是一个很强大的iOS View Hierarchy工具,与 ...
- 转:LIRE的使用
LIRE的使用:创建索引 LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引.利用该索引就能够构建一个基于内容的图像检索(content- ...
- ASP怎么解除文件上传200kb限制
第一步:修改IIS设置,允许直接编辑配置数据库.打开,Internet信息服务第二步:先在服务里关闭iis admin service服务,找到windows\system32\inetsrv\下的m ...
- Directx11教程(14) D3D11管线(2)
下面我们来了解一些GPU memory的知识,主要参考资料:http://fgiesen.wordpress.com/0211/07/02/a-trip-through-the-graphics-pi ...