RadCartesianChart LinearAxis DateFormat Germany?

2 Answers 46 Views
ChartView
BerndR
Top achievements
Rank 1
Iron
BerndR asked on 17 Jun 2024, 10:10 AM | edited on 17 Jun 2024, 10:10 AM

Hi,

i found a sample:


    <Window.Resources>
        <local:DoubleToDateTimeLabelConverter x:Key="DoubleToDateTimeLabelConverter" />
    </Window.Resources>
    <Grid>
        <telerik:RadCartesianChart>
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:LinearAxis>
                    <telerik:LinearAxis.LabelTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding StringFormat='h:MM tt', Converter={StaticResource DoubleToDateTimeLabelConverter}}" />
                        </DataTemplate>
                    </telerik:LinearAxis.LabelTemplate>
                </telerik:LinearAxis>
            </telerik:RadCartesianChart.HorizontalAxis>
            
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:CategoricalAxis />
            </telerik:RadCartesianChart.VerticalAxis>
            
            <telerik:LineSeries CategoryBinding="City" ValueBinding="StartTimeOA" ItemsSource="{Binding}" />
        </telerik:RadCartesianChart>
    </Grid>


        public MainWindow()
        {
            InitializeComponent();

            var Items = new ObservableCollection<PlotItemViewModel>();
            var dateTime = DateTime.Now;
            Items.Add(new PlotItemViewModel() { City = "Atlanta", StartTime = dateTime.AddMinutes(5) });
            Items.Add(new PlotItemViewModel() { City = "Atlanta", StartTime = dateTime.AddMinutes(10), });
            Items.Add(new PlotItemViewModel() { City = "New York", StartTime = dateTime.AddMinutes(100), });
            Items.Add(new PlotItemViewModel() { City = "Miami", StartTime = dateTime.AddMinutes(120), });
            Items.Add(new PlotItemViewModel() { City = "Miami", StartTime = dateTime.AddMinutes(150), });
            Items.Add(new PlotItemViewModel() { City = "Savannah", StartTime = dateTime.AddMinutes(200), });
            Items.Add(new PlotItemViewModel() { City = "Birmingham", StartTime = dateTime.AddMinutes(250), });
            Items.Add(new PlotItemViewModel() { City = "New Orleans", StartTime = dateTime.AddMinutes(280), });

            this.DataContext = Items;
        }
    }

    public class PlotItemViewModel
    {
        public string City { get; set; }
        public DateTime StartTime { get; set; }
        public double StartTimeOA { get { return this.StartTime.ToOADate(); } }
    }

    public class DoubleToDateTimeLabelConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double doubleValue = double.Parse(value.ToString());
            return DateTime.FromOADate(doubleValue);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

The Result is:

Here is the Dateformat "us-US" (10:05 AM / 4:06 PM) but i need German "de-DE" (10:05 / 16:06) !

Have anyone a idea how i can do this?

Best regards

Bernd

 

 

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 18 Jun 2024, 02:00 PM

Hello Bernd,

To achieve your requirement, you can call ToString() with German culture info in the Convert method. For example:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
	double doubleValue = double.Parse(value.ToString());	
	return DateTime.FromOADate(doubleValue).ToString(new CultureInfo("de-DE"));
}

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
BerndR
Top achievements
Rank 1
Iron
answered on 19 Jun 2024, 07:32 AM

Nearly :-)

Now i need only the Time ;-)

 

 

 

BerndR
Top achievements
Rank 1
Iron
commented on 19 Jun 2024, 07:41 AM

I got it!

return DateTime.FromOADate(doubleValue).ToString("HH:mm", new CultureInfo("de-DE"));

Thanks a lot :-)
BerndR
Top achievements
Rank 1
Iron
commented on 19 Jun 2024, 07:44 AM

Now i have for me the right time :-)

Martin Ivanov
Telerik team
commented on 19 Jun 2024, 12:46 PM

Great to hear that. Thanks for sharing your solution.
Tags
ChartView
Asked by
BerndR
Top achievements
Rank 1
Iron
Answers by
Martin Ivanov
Telerik team
BerndR
Top achievements
Rank 1
Iron
Share this question
or