The Visiblox Charts component also supports internationalisation, as shown by this example.
Switch languages by selecting from the radio buttons.
Note that this example uses data from an external data source not included in the code snippets - download the examples source code in full to view the data.
XAML + CODE +
<UserControl xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
x:Class="Visiblox.Charts.Examples.Internationalization.InternationalizationExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:charts="clr-namespace:Visiblox.Charts;assembly=Visiblox.Charts"
mc:Ignorable="d">
<UserControl.Resources>
<Style x:Key="NoBorder" TargetType="Border">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="BorderBrush" Value="Black" />
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Vertical">
<!-- Error Message for uninstalled locales-->
<Border BorderBrush="DarkRed" BorderThickness="1" x:Name="ErrorMessagePanel" Height="30">
<TextBlock Margin="10,0,10,0" VerticalAlignment="Center" x:Name="ErrorMessage" HorizontalAlignment="Left">
This locale is not installed on your computer thus can't be viewed correctly. Please select another one to view.</TextBlock>
</Border>
<!-- Ultimate Trial users should add 'ValidationKey="ENTER TRIAL LICENSE KEY HERE"' to each Chart declaration. -->
<charts:Chart Grid.Row="1" x:Name="Chart" Width="600" Height="350" Title="Exchange Rates for GBP/JPY" HorizontalAlignment="Center" LegendVisibility="Collapsed"
PlotAreaBorderStyle="{StaticResource NoBorder}" >
<charts:Chart.XAxis>
<charts:DateTimeAxis MajorTickIntervalType="Months" MajorTickInterval="3" ShowMinorTicks="False" ShowMajorGridlines="False" LabelFormatString="MMM yyy" />
</charts:Chart.XAxis>
<charts:Chart.YAxis>
<charts:LinearAxis ShowMinorTicks="False" LabelFormatString="N0" ShowMajorGridlines="False" />
</charts:Chart.YAxis>
</charts:Chart>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<RadioButton IsChecked="True" Tag="British English" Checked="Culture_CheckChanged" Margin="0,0,20,0">British English</RadioButton>
<RadioButton IsChecked="False" Tag="Czech" Checked="Culture_CheckChanged" Margin="0,0,20,0">Czech</RadioButton>
<RadioButton IsChecked="False" Tag="Hungarian" Checked="Culture_CheckChanged" Margin="0,0,20,0">Hungarian</RadioButton>
<RadioButton IsChecked="False" Tag="French" Checked="Culture_CheckChanged" Margin="0,0,20,0">French</RadioButton>
<RadioButton IsChecked="False" Tag="Russian" Checked="Culture_CheckChanged" Margin="0,0,20,0">Russian</RadioButton>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>
^ Back To Top
using System;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
namespace Visiblox.Charts.Examples.Internationalization
{
public partial class InternationalizationExample : UserControl
{
private static Culture defaultCulture = new Culture { Description = "British English", Name = "en-GB", YAxisLabel = "Price", ChartTitle = "Exchange Rate (GBP/JPY)" };
private Dictionary<string, Culture> cultures = new Dictionary<string, Culture>();
public InternationalizationExample()
{
InitializeComponent();
// Define data series
var lineSeries = new LineSeries() { LineStrokeThickness = 1.5, ShowPoints = true, ToolTipEnabled = true };
lineSeries.DataSeries = GenerateDataSeries();
Chart.Series.Add(lineSeries);
// Define culture entries for the combo box
cultures.Add("British English", defaultCulture);
cultures.Add("Czech", new Culture { Description = "Czech", Name = "cs-CZ", YAxisLabel = "Cena", ChartTitle = "Kurz (GBP/JPY)" });
cultures.Add("Hungarian", new Culture { Description = "Hungarian", Name = "hu-HU", YAxisLabel = "Ár", ChartTitle = "Árfolyam (GBP/JPY)" });
cultures.Add("French", new Culture { Description = "French", Name = "fr-FR", YAxisLabel = "Prix", ChartTitle = "Taux de change (GBP/JPY)" });
cultures.Add("Russian", new Culture { Description = "Russian", Name = "ru-RU", YAxisLabel = "Цена", ChartTitle = "Обмен валюты (GBP/JPY)" });
SetCulture(defaultCulture);
}
private IDataSeries GenerateDataSeries()
{
var series = new DataSeries<DateTime, double>();
//open stream of data file
using (StreamReader streamReader = new StreamReader(ExampleHelpers.GetApplicationResourceStream("Internationalization/Data/gbpjpy.csv").Stream))
{
// Read through the csv file and fill up dataSeries with the data
{
streamReader.ReadLine();
while (streamReader.Peek() >= 0)
{
string line = streamReader.ReadLine();
string[] values = line.Split(',');
String[] dateParts = values[0].Split('/');
DateTime date = new DateTime(int.Parse(dateParts[2]), int.Parse(dateParts[0]), int.Parse(dateParts[1]));
double price = double.Parse(values[1]);
series.Add(new DataPoint<DateTime, double>(date, price));
}
}
}
return series;
}
private void Culture_CheckChanged(object sender, RoutedEventArgs e)
{
var button = sender as RadioButton;
if (button != null && Chart != null)
{
var selectedCulture = button.Tag == null ? defaultCulture : cultures[button.Tag.ToString()];
SetCulture(selectedCulture);
}
}
private void SetCulture(Culture culture)
{
try
{
Chart.YAxis.Title = culture.YAxisLabel;
Chart.XAxis.Title = culture.XAxisLabel;
Chart.Title = culture.ChartTitle;
Chart.XAxis.LabelFormatString = culture.LongDatePattern;
ErrorMessagePanel.Visibility = Visibility.Collapsed;
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture.Name);
Chart.Invalidate();
}
catch (ArgumentException)
{
ErrorMessagePanel.Visibility = Visibility.Visible;
}
}
// Data Model
/// <summary>
/// Class to store cultures to use on chart
/// </summary>
public class Culture
{
public string Name { get; set; }
public string Description { get; set; }
public string YAxisLabel { get; set; }
public string XAxisLabel { get; set; }
public string ChartTitle { get; set; }
public string LongDatePattern
{
get { return new CultureInfo(Name).DateTimeFormat.LongDatePattern; }
}
public override string ToString()
{
return Description;
}
}
}
}
^ Back To Top

