Uso de la clase ChartGlobalizationSettings para establecer diferentes idiomas para componentes del gráfico con C++
Escenarios de uso posibles
Las API de Aspose.Cells han expuesto la clase ChartGlobalizationSettings para tratar los escenarios en los que el usuario desea establecer el componente del gráfico en un idioma diferente, como etiquetas personalizadas para subtotales en una hoja de cálculo.
Introducción a la clase ChartGlobalizationSettings
La clase ChartGlobalizationSettings actualmente ofrece los siguientes 8 métodos que pueden ser sobrescritos en una clase personalizada para traducir, como el nombre del Título del Eje, el nombre de la Unidad del Eje, el nombre del Título del Gráfico, y otros a diferentes idiomas.
- GetAxisTitleName: Obtiene el nombre del Título para el Eje.
- GetAxisUnitName: Obtiene el nombre de la Unidad del Eje.
- GetChartTitleName: Obtiene el nombre del Título del Gráfico.
- GetLegendDecreaseName: Obtiene el nombre de Disminución para la Leyenda.
- GetLegendIncreaseName: Obtiene el nombre de Aumento para la Leyenda.
- GetLegendTotalName: Obtiene el nombre de Total para la Leyenda.
- GetOtherName: Obtiene el nombre de las etiquetas “Otro” para el Gráfico.
- GetSeriesName: Obtiene el nombre de la Serie en el Gráfico.
Traducción personalizada de idioma
Aquí, crearemos un gráfico de cascada basado en los siguientes datos. Los nombres de los componentes del gráfico se mostrarán en inglés en el gráfico. Utilizaremos un ejemplo en idioma turco para mostrar cómo mostrar el Título del Gráfico, los nombres de Aumento/Disminución de la Leyenda, el nombre de Total y el Título del Eje en turco.
Código de muestra
El siguiente código de ejemplo carga el archivo de Excel de muestra.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Charts;
class TurkeyChartGlobalizationSettings : public ChartGlobalizationSettings
{
public:
TurkeyChartGlobalizationSettings() : ChartGlobalizationSettings() {}
U16String GetChartTitleName() override
{
return u"Grafik Başlığı"; // Chart Title
}
U16String GetLegendIncreaseName() override
{
return u"Artış"; // Increase
}
U16String GetLegendDecreaseName() override
{
return u"Düşüş"; // Decrease
}
U16String GetLegendTotalName() override
{
return u"Toplam"; // Total
}
U16String GetAxisTitleName() override
{
return u"Eksen Başlığı"; // Axis Title
}
};
void ChartGlobalizationSettingsTest()
{
// Create an instance of existing Workbook
U16String pathName = u"input.xlsx";
Workbook workbook(pathName);
// Set custom chartGlobalizationSettings, here is TurkeyChartGlobalizationSettings
TurkeyChartGlobalizationSettings* globalizationSettings = new TurkeyChartGlobalizationSettings();
workbook.GetSettings().GetGlobalizationSettings()->SetChartSettings(globalizationSettings);
// Get the worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Load the chart from source worksheet
ChartCollection chartCollection = worksheet.GetCharts();
Chart chart = chartCollection.Get(0);
// Chart Calculate
chart.Calculate();
// Get the chart title
Title title = chart.GetTitle();
// Output the name of the Chart title
std::cout << "\nWorkbook chart title: " << title.GetText().ToUtf8() << std::endl;
// Get the legend labels
Vector<U16String> legendEntriesLabels = chart.GetLegend().GetLegendLabels();
// Output the name of the Legend
for (int i = 0; i < legendEntriesLabels.GetLength(); i++)
{
std::cout << "\nWorkbook chart legend: " << legendEntriesLabels[i].ToUtf8() << std::endl;
}
// Output the name of the Axis title
Title categoryAxisTitle = chart.GetCategoryAxis().GetTitle();
std::cout << "\nWorkbook category axis title: " << categoryAxisTitle.GetText().ToUtf8() << std::endl;
delete globalizationSettings;
}
int main()
{
Aspose::Cells::Startup();
ChartGlobalizationSettingsTest();
Aspose::Cells::Cleanup();
return 0;
}
Resultado generado por el código de ejemplo
Este es el resultado de consola del código de ejemplo anterior.
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ığı