我正在尝试使用C#的Aspose.Cells设置条形图的轴比例。我目前正在做的基本上是这样的:
var chart = worksheet.Charts.Add(ChartType.BarChart, 1, 1, 15, 15)
chart.NSeries.AddSeries("{.015,.03,.04}", true)
chart.NSeries.CategoryData = "{Apples,Oranges,Pears}"
chart.SeriesAxis.IsAutomaticMajorUnit = false;
chart.SeriesAxis.MajorUnit = .01;
但是,当电子表格呈现时,图表的主要单位刻度会自动设置为.1,因此所有的条形图看起来都不成比例地小。如何更改系列轴的比例,使其具有由.01分隔的刻度线?
发布于 2018-06-05 09:10:09
请根据您的需要使用以下代码。
C#
//Set the major unit to 0.01
ch.ValueAxis.IsAutomaticMajorUnit = false;
ch.ValueAxis.MajorUnit = 0.01;
下面是完整的示例代码和显示由代码生成的输出Excel文件的屏幕截图,供您参考。
C#
// Create empty workbook.
Workbook wb = new Workbook();
// Access first worksheet.
Worksheet worksheet = wb.Worksheets[0];
// Add Bar chart in first worksheet.
int idx = worksheet.Charts.Add(ChartType.Bar, 5, 2, 20, 10);
// Access Bar chart.
Chart ch = worksheet.Charts[0];
// Add two number series, true means they are vertical.
ch.NSeries.Add("{.015,.03,.04}", true);
// Set the category data to show on X-axis.
ch.NSeries.CategoryData = "{Apples,Oranges,Pears}";
// Set the name of first and second series.
ch.NSeries[0].Name = "Cricket";
//Set the major unit to 0.01
ch.ValueAxis.IsAutomaticMajorUnit = false;
ch.ValueAxis.MajorUnit = 0.01;
// Save the output in xlsx format.
wb.Save("outputBarChart.xlsx", SaveFormat.Xlsx);
备注:我在Aspose担任开发人员布道员
https://stackoverflow.com/questions/50689585
复制相似问题