将图表转换为中国区域的图像

定义继承类

第一步,您需要定义一个从 ChartGlobalizationSettings 继承的类 “ChartChineseSetttings”。 然后,通过重写相关函数,您可以将图表元素的文本设置为您自己的语言。 代码示例:

using System;
using System.Collections.Generic;
using System.Text;
using Aspose.Cells.Charts;
namespace ChartGlobalizationSettingsTest
{
public class ChartChineseSetttings: ChartGlobalizationSettings
{
public override string GetAxisTitleName()
{
return "坐标轴标题";
}
public override string GetAxisUnitName(DisplayUnitType type)
{
switch (type)
{
case DisplayUnitType.None:
return string.Empty;
case DisplayUnitType.Hundreds:
return "百";
case DisplayUnitType.Thousands:
return "千";
case DisplayUnitType.TenThousands:
return "万";
case DisplayUnitType.HundredThousands:
return "十万";
case DisplayUnitType.Millions:
return "百万";
case DisplayUnitType.TenMillions:
return "千万";
case DisplayUnitType.HundredMillions:
return "亿";
case DisplayUnitType.Billions:
return "十亿";
case DisplayUnitType.Trillions:
return "兆";
default:
return string.Empty;
}
}
public override string GetChartTitleName()
{
return "图表标题";
}
public override string GetLegendDecreaseName()
{
return "减少";
}
public override string GetLegendIncreaseName()
{
return "增加";
}
public override string GetLegendTotalName()
{
return "汇总";
}
public override string GetOtherName()
{
return "其他";
}
public override string GetSeriesName()
{
return "系列";
}
}
}

为图表配置中文设置

在这一步,您将使用在前一步中定义的类 “ChartChineseSetttings”。 代码示例:

	Workbook wb = new Workbook("Chinese.xls");
	wb.Settings.GlobalizationSettings.ChartSettings = new ChartChineseSetttings();
	Chart chart0 = wb.Worksheets[0].Charts[0];
	chart0.ToImage("Output.png");

然后,您可以在输出图像中看到效果,图表中的元素将根据您的设置进行渲染。

结论

在这个示例中,如果不为图表设置中国区域,则以下图表元素可能以默认语言(例如英语)渲染。 在上述操作之后,我们可以获得一个带有中国区域的输出图表图片。

支持的元素 本示例中的值 英文环境中的默认值
轴标题名称 坐标轴标题 Axis Title
轴单位名称 百,千… Hundreds, Thousands…
图表标题 图表标题
增加 增加
减少 减少
汇总 汇总
其他 其他
系列 系列