使用ChartGlobalizationSettings类通过Node.js与C++设置图表组件的多语言
Contents
[
Hide
]
可能的使用场景
Aspose.Cells API已公开ChartGlobalizationSettings类,以应对用户希望为电子表格中的图表组件设置不同语言和自定义标签(如小计标签)的场景。
ChartGlobalizationSettings类介绍
ChartGlobalizationSettings类目前提供以下8个可在自定义类中重写的方法,用于翻译如AxisTitle名称、AxisUnit名称、ChartTitle名称等到不同语言。
- ChartGlobalizationSettings.getAxisTitleName():获取轴的标题名称。
- ChartGlobalizationSettings.getAxisUnitName(DisplayUnitType):获取轴单位的名称。
- ChartGlobalizationSettings.getChartTitleName():获取图表标题的名称。
- ChartGlobalizationSettings.getLegendDecreaseName():获取图例减少的名称。
- ChartGlobalizationSettings.getLegendIncreaseName(): 获取图例中的“增加”名称。
- ChartGlobalizationSettings.getLegendTotalName():获取图例的总名称。
- ChartGlobalizationSettings.getOtherName():获取图表中“其他”标签的名称。
- ChartGlobalizationSettings.getSeriesName():获取图表中系列的名称。
自定义语言翻译
在这里,我们将根据以下数据创建瀑布图。图表中将以英语显示图表组件的名称。我们将使用土耳其语示例来展示如何在图表中显示图表标题、图例增加/减少名称、总计名称和轴标题。
示例代码
以下示例代码加载了示例Excel文件。
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);
示例代码生成的输出
这是上述示例代码的控制台输出。
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ığı