如何在 Aspose 图的 x 轴上显示自定义标签?
How to show custom labels in x-axis of Aspose graphs?
我有一个 aspose Column3DClustered graph.Currently x 轴显示数字值,只说 1,2...我想显示一些标签,如 "Apple"、"Orange"等等..而不是 1,2etc..我怎样才能使用 aspose 实现这个?
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells[0, 0].PutValue(1);
worksheet.Cells[0, 1].PutValue(50);
worksheet.Cells[0, 2].PutValue(100);
worksheet.Cells[1, 0].PutValue(2);
worksheet.Cells[1, 1].PutValue(50);
worksheet.Cells[1, 2].PutValue(20);
int chartIndex = worksheet.Charts.Add(ChartType.Column3DClustered, 5, 0, 15, 5);
Chart chart = worksheet.Charts[chartIndex];
chart.Title.Text = "Fruits for period 6/2016";
chart.Title.Font.Size = 6;
chart.NSeries.Add("B1:B2", true);
chart.NSeries.Add("C1:C2", true);
chart.NSeries[0].Name = "Total Quantity";
chart.NSeries[1].Name = "Net Available";
chart.NSeries[0].DataLabels.ShowValue = true;
chart.NSeries[0].DataLabels.Font.Size = 6;
chart.NSeries[0].Area.ForegroundColor = Color.DeepSkyBlue;
chart.NSeries[1].DataLabels.ShowValue = true;
chart.NSeries[1].DataLabels.Font.Size = 6;
chart.NSeries[1].Area.ForegroundColor = Color.MediumPurple;
chart.Legend.Position = LegendPositionType.Bottom;
chart.Legend.Font.Size = 6;
请根据您的需要使用Chart.NSeries.CategoryData。请参阅以下示例代码。它加载示例 Excel 文件并更改 类别数据,即图表的 X 轴 并将其保存为输出 Excel 文件。
C#
//Load the sample Excel file.
Workbook wb = new Workbook("Sample.xlsx");
//Access first worksheet.
Worksheet ws = wb.Worksheets[0];
//Access first chart.
Chart ch = ws.Charts[0];
//Change the category data - X axis values.
ch.NSeries.CategoryData = "=Sheet1!$C:$C";
//Save the output Excel file.
wb.Save("Output.xlsx");
请看这张图片。它显示了示例 Excel 文件、输出 Excel 文件以及代码对它们的影响,供您参考。
注意:我在 Aspose 担任开发人员布道师
我有一个 aspose Column3DClustered graph.Currently x 轴显示数字值,只说 1,2...我想显示一些标签,如 "Apple"、"Orange"等等..而不是 1,2etc..我怎样才能使用 aspose 实现这个?
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells[0, 0].PutValue(1);
worksheet.Cells[0, 1].PutValue(50);
worksheet.Cells[0, 2].PutValue(100);
worksheet.Cells[1, 0].PutValue(2);
worksheet.Cells[1, 1].PutValue(50);
worksheet.Cells[1, 2].PutValue(20);
int chartIndex = worksheet.Charts.Add(ChartType.Column3DClustered, 5, 0, 15, 5);
Chart chart = worksheet.Charts[chartIndex];
chart.Title.Text = "Fruits for period 6/2016";
chart.Title.Font.Size = 6;
chart.NSeries.Add("B1:B2", true);
chart.NSeries.Add("C1:C2", true);
chart.NSeries[0].Name = "Total Quantity";
chart.NSeries[1].Name = "Net Available";
chart.NSeries[0].DataLabels.ShowValue = true;
chart.NSeries[0].DataLabels.Font.Size = 6;
chart.NSeries[0].Area.ForegroundColor = Color.DeepSkyBlue;
chart.NSeries[1].DataLabels.ShowValue = true;
chart.NSeries[1].DataLabels.Font.Size = 6;
chart.NSeries[1].Area.ForegroundColor = Color.MediumPurple;
chart.Legend.Position = LegendPositionType.Bottom;
chart.Legend.Font.Size = 6;
请根据您的需要使用Chart.NSeries.CategoryData。请参阅以下示例代码。它加载示例 Excel 文件并更改 类别数据,即图表的 X 轴 并将其保存为输出 Excel 文件。
C#
//Load the sample Excel file.
Workbook wb = new Workbook("Sample.xlsx");
//Access first worksheet.
Worksheet ws = wb.Worksheets[0];
//Access first chart.
Chart ch = ws.Charts[0];
//Change the category data - X axis values.
ch.NSeries.CategoryData = "=Sheet1!$C:$C";
//Save the output Excel file.
wb.Save("Output.xlsx");
请看这张图片。它显示了示例 Excel 文件、输出 Excel 文件以及代码对它们的影响,供您参考。
注意:我在 Aspose 担任开发人员布道师