Free Support Forum - aspose.com

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?

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;

@anishsm,

Thanks for the sample code.

Well, you may input your desired custom data into the relevant cells and then set the category data for the data series collection. See the updated sample code segment for your reference:
e.g
Sample code:

Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Cells[0, 0].PutValue("Apple");
            worksheet.Cells[0, 1].PutValue(50);
            worksheet.Cells[0, 2].PutValue(100);

            worksheet.Cells[1, 0].PutValue("Orange");
            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.CategoryData = "A1:A2";

            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;

Hope, this helps a bit.

Thank you.Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Cells[0, 0].PutValue("Apple");
            worksheet.Cells[0, 1].PutValue(50);
            worksheet.Cells[0, 2].PutValue(100);

            worksheet.Cells[1, 0].PutValue("Orange");
            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.CategoryData = "A1:A2";

            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;

Hope, this helps a bit.

1 Like

It worked fine.Thank you so much

@anishsm,

Good to know that the suggested code figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.