Using ChartGlobalizationSettings Class to Set Different Language for Chart Component

Possible Usage Scenarios

Aspose.Cells APIs have exposed the ChartGlobalizationSettings class in order to deal with the scenarios where the user wishes to set chart component to different language. custom labels for Subtotals in a spreadsheet.

Introduction to ChartGlobalizationSettings Class

The ChartGlobalizationSettings class currently offers the following 8 methods which can be overridden in a custom class to translate such as AxisTitle name,AxisUnit name,ChartTitle name and so on to different language.

  1. GetAxisTitleName: Gets the name of Title for Axis.
  2. GetAxisUnitName: Gets the Name of Axis Unit.
  3. GetChartTitleName: Gets the name of Chart Title.
  4. GetLegendDecreaseName: Gets the name of Decrease for Legend.
  5. GetLegendIncreaseName: Gets the name of increase for Legend.
  6. GetLegendTotalName: Gets the name of Total for Legend.
  7. GetOtherName: Gets the name of “Other” labels for Chart.
  8. GetSeriesName: Gets the name of Series in the Chart.

Custom language translation

Here, we will create a waterfall chart based on the following data. The names of chart components will be displayed in English in the chart. We will use a Turkish language example to show how to display the Chart Title, Legend Increase/Decrease names, Total name, and Axis Title in Turkish.

todo:image_alt_text

Sample Code

The following sample code loads the sample Excel file.

//Create a custom language class for chart component,here take Turkey for example,
//which will translate the chart element to specific language
public class TurkeyChartGlobalizationSettings : ChartGlobalizationSettings
{
public override string GetChartTitleName()
{
return "Grafik Başlığı";//Chart Title
}
public override string GetLegendIncreaseName()
{
return "Artış";//Increase
}
public override string GetLegendDecreaseName()
{
return "Düşüş";//Decrease;
}
public override string GetLegendTotalName()
{
return "Toplam";//Total
}
public override string GetAxisTitleName()
{
return "Eksen Başlığı";//Axis Title
}
}
public static void ChartGlobalizationSettingsTest()
{
//Create an instance of existing Workbook
string pathName = "input.xlsx";
Workbook workbook = new Workbook(pathName);
//Set custom chartGlobalizationSettings, here is TurkeyChartGlobalizationSettings
workbook.Settings.GlobalizationSettings.ChartSettings = new TurkeyChartGlobalizationSettings();
//Get the worksheet
Worksheet worksheet = workbook.Worksheets[0];
ChartCollection chartCollection = worksheet.Charts;
//Load the chart from source worksheet
Chart chart = chartCollection[0];
//Chart Calculate
chart.Calculate();
//Get the chart title
Title title = chart.Title;
//Output the name of the Chart title
Console.WriteLine("\nWorkbook chart title: " + title.Text);
string[] legendEntriesLabels = chart.Legend.GetLegendLabels();
//Output the name of the Legend
for (int i = 0; i < legendEntriesLabels.Length; i++)
{
Console.WriteLine("\nWorkbook chart legend: " + legendEntriesLabels[i]);
}
//Output the name of the Axis title
Title categoryAxisTitle = chart.CategoryAxis.Title;
Console.WriteLine("\nWorkbook category axis tile: " + categoryAxisTitle.Text);
}

Output generated by the sample code

This is the console output of the above sample code.

Workbook chart title: Grafik Başlığı

Workbook chart legend: Artış

Workbook chart legend: Düşüş

Workbook chart legend: Toplam

Workbook category axis tile: Eksen Başlığı