ChartGlobalizationSettingsクラスを使用して、チャートコンポーネントの異なる言語を設定する方法

可能な使用シナリオ

Aspose.CellsのAPIは、ユーザーがチャートコンポーネントを異なる言語に設定したい場合に取り扱うために、ChartGlobalizationSettingsクラスを公開しています。スプレッドシート内の小計のカスタムラベル。

ChartGlobalizationSettingsクラスの紹介

ChartGlobalizationSettingsクラスは現在、異なる言語に翻訳するためのカスタムクラスでオーバーライドできる8つのメソッドを提供します。例えば、AxisTitle名、AxisUnit名、ChartTitle名など。

  1. GetAxisTitleName:軸タイトルの名前を取得します。
  2. GetAxisUnitName:軸単位の名前を取得します。
  3. GetChartTitleName:チャートタイトルの名前を取得します。
  4. GetLegendDecreaseName:凡例の減少の名前を取得します。
  5. GetLegendIncreaseName:凡例の増加の名前を取得します。
  6. GetLegendTotalName:凡例の合計の名前を取得します。
  7. GetOtherName:チャートの「その他」ラベルの名前を取得します。
  8. GetSeriesName:チャート内の系列の名前を取得します。

カスタム言語の翻訳

以下、次のデータを元にウォーターフォールチャートを作成します。チャートコンポーネントの名前は、チャート内で英語で表示されます。チャートタイトル、凡例の増減名、合計名、および軸タイトルのトルコ語表示方法を示すためにトルコ語の例を使用します。

todo:image_alt_text

サンプルコード

次のサンプルコードは、サンプルExcelファイルを読み込みます。

//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);
}

サンプルコードによって生成された出力

これは上記のサンプルコードのコンソール出力です。

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ığı