简体   繁体   English

如何在Aspose图的x轴上显示自定义标签?

[英]How to show custom labels in x-axis of Aspose graphs?

I have a aspose Column3DClustered graph.Currently the x-axis is showing values in numbers only say 1,2...I want to show some labels like "Apple","Orange" etc..instead of 1,2etc..How can I achieve this using aspose? 我有一个aspose Column3DClustered图。当前,x轴显示的数值仅表示1,2 ...我想显示一些标签,例如“ Apple”,“ Orange”等。而不是1,2等。我可以使用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;

Please use Chart.NSeries.CategoryData for your needs. 请根据需要使用Chart.NSeries.CategoryData Please see the following sample code. 请参见以下示例代码。 It loads the sample Excel file and changes Category Data ie X-axis of the chart and saves it as output Excel file. 它加载示例Excel文件并更改类别数据(即图表的X轴)并将其保存为输出Excel文件。

C# 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$1:$C$4";

//Save the output Excel file.
wb.Save("Output.xlsx");

Please see this image. 请看这张图片。 It shows the sample Excel file, output Excel file and the effect of the code on them for your reference. 它显示了示例Excel文件,输出Excel文件以及代码对它们的影响,以供您参考。

使用Aspose.Cells API更改Chart的CategoryData X轴

Note: I am working as Developer Evangelist at Aspose 注意: 我在Aspose担任开发人员布道者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM