Utilizzo della classe ChartGlobalizationSettings per impostare lingue differenti per il componente grafico con Node.js tramite C++
Possibili Scenari di Utilizzo
Le API di Aspose.Cells hanno esposto la classe ChartGlobalizationSettings per gestire gli scenari in cui l’utente desidera impostare componenti del grafico in lingue diverse e etichette personalizzate per i subtotali in un foglio di calcolo.
Introduzione alla classe ChartGlobalizationSettings
La classe ChartGlobalizationSettings attualmente offre i seguenti 8 metodi che possono essere sovrascritti in una classe personalizzata per tradurre nomi come AxisTitle, AxisUnit, ChartTitle e altri in diverse lingue.
- ChartGlobalizationSettings.getAxisTitleName(): Ottiene il nome del Titolo per l’Asse.
- ChartGlobalizationSettings.getAxisUnitName(DisplayUnitType): Ottiene il Nome dell’Unità di Asse.
- ChartGlobalizationSettings.getChartTitleName(): Ottiene il nome del Titolo del Grafico.
- ChartGlobalizationSettings.getLegendDecreaseName(): Ottiene il nome di Diminuzione per la Leggenda.
- ChartGlobalizationSettings.getLegendIncreaseName(): Ottiene il nome di Increase per la legenda.
- ChartGlobalizationSettings.getLegendTotalName(): Ottiene il nome di Totale per la Leggenda.
- ChartGlobalizationSettings.getOtherName(): Ottiene il nome delle etichette “Altro” per il Grafico.
- ChartGlobalizationSettings.getSeriesName(): Ottiene il nome di Serie nel Grafico.
Traduzione personalizzata
Qui, creeremo un grafico a barre basato sui seguenti dati. I nomi dei componenti del grafico verranno visualizzati in inglese nel grafico. Useremo un esempio in lingua turca per mostrare come visualizzare il Titolo del Grafico, i nomi di Aumento/Diminuzione della Leggenda, il nome Totale e il Titolo dell’Asse in turco.
Codice di Esempio
Il seguente codice di esempio carica il file Excel di esempio.
try {
const path = require("path");
const AsposeCells = require("aspose.cells.node");
class TurkeyChartGlobalizationSettings extends AsposeCells.ChartGlobalizationSettings {
getChartTitleName() {
return "Grafik Başlığı"; // Chart Title
}
getLegendIncreaseName() {
return "Artış"; // Increase
}
getLegendDecreaseName() {
return "Düşüş"; // Decrease
}
getLegendTotalName() {
return "Toplam"; // Total
}
getAxisTitleName() {
return "Eksen Başlığı"; // Axis Title
}
}
async function chartGlobalizationSettingsTest() {
// Create an instance of existing Workbook
const dataDir = path.join(__dirname, "data");
const pathName = path.join(dataDir, "input.xlsx");
const workbook = new AsposeCells.Workbook(pathName);
// Set custom chartGlobalizationSettings, here is TurkeyChartGlobalizationSettings
workbook.getSettings().getGlobalizationSettings().setChartSettings(new TurkeyChartGlobalizationSettings());
// Get the worksheet
const worksheet = workbook.getWorksheets().get(0);
const chartCollection = worksheet.getCharts();
// Load the chart from source worksheet
const chart = chartCollection.get(0);
// Chart Calculate
chart.calculate();
// Get the chart title
const title = chart.getTitle();
console.log("\nWorkbook chart title: " + title.getText());
const legendEntriesLabels = chart.getLegend().getLegendLabels();
// Output the name of the Legend
legendEntriesLabels.forEach(label => {
console.log("\nWorkbook chart legend: " + label);
Output generato dal codice di esempio
Questo è l’output console del codice di esempio precedente.
Workbook chart title: Grafik Başlığı
Workbook chart legend: Artış
Workbook chart legend: Düşüş
Workbook chart legend: Toplam
Workbook category axis title: Eksen Başlığı