This is a migrated thread and some comments may be shown as answers.

Force the last chart tick to have a label

5 Answers 251 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 20 Jan 2018, 03:20 PM

We are binding data collections to a ChartView. The data collections contain measurements taken over a period of time. Those time periods (currently) are four hours, one day, one week and one month. 

When the user chooses a different time period, we refresh the collection and change some of the chart properties to make more sense (LabelFormat, LabelInterval). But because the number of measurements can vary the LabelInterval may end up causing the last gridpoint to not have a label. (I have attached screenshots of a sample showing month, week, day, and four hour renderings.

Is there any way to force the last label to show no matter how many datapoints there are?

 

<telerik:RadCartesianChart x:Name="radChart" Margin="0,0,0,0" Height="340">
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:DateTimeContinuousAxis
            LabelInterval="{Binding ChartSettingsViewModel.LabelInterval}"
            LabelFormat="{Binding ChartSettingsViewModel.LabelFormat}"
            PlotMode="OnTicksPadded"
            >
        </telerik:DateTimeContinuousAxis>
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis Title="{Binding SeriesTitle}">
        </telerik:LinearAxis>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.Grid>
        <telerik:CartesianChartGrid MajorLinesVisibility="Y" MajorYLineDashArray="3,4" StripLinesVisibility="Y" />
    </telerik:RadCartesianChart.Grid>
    <telerik:RadCartesianChart.Series>
        <chartView:LineSeries ItemsSource="{Binding Measurements}" Stroke="{Binding LineColor}">
            <chartView:LineSeries.ValueBinding>
                <telerik:PropertyNameDataPointBinding PropertyName="Value"/>
            </chartView:LineSeries.ValueBinding>
            <chartView:LineSeries.CategoryBinding>
                <telerik:PropertyNameDataPointBinding PropertyName="LocalDateTime"/>
            </chartView:LineSeries.CategoryBinding>
        </chartView:LineSeries>
    </telerik:RadCartesianChart.Series>
</telerik:RadCartesianChart>

5 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 24 Jan 2018, 11:48 AM
Hello Paul,

To achieve your requirement you can set the Maximum of the axis to a value that can be multiplied by the label interval. For example, if the axis was numerical and it has the range between 1 and 11 and you apply an interval of 3, you will get labels on the following values: 1, 5, 9. There won't be a label for the last value. But, if you extend the maximum a bit you will get a label position there. For example, you can set the maximum to 13.

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Paul
Top achievements
Rank 1
answered on 24 Jan 2018, 12:32 PM
But, it is a time-based axis. And the maximum time is determined by the measurements that are bound to the grid. I understand how your solution would work for a static axis, but I don't understand how I would do it for this scenario.
0
Martin Ivanov
Telerik team
answered on 24 Jan 2018, 01:45 PM
Hello Paul,

The same approach could work also with the DateTimeContinuousAxis but I haven't taken into account that the auto calculated major step of the axis will change when you change the maximum. To get the desired functionality you can manually calculate and set the Minimum, Maximum, MajorStep and MajorStepUnit properties of the axis so that the range meets your requirement. As an alternative approach for showing a label on the maximum regardless of the label interval you can use a custom annotation and draw it on the maximum value. You can get the actual maximum when the axis is auto ranged via its ActualRange property.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Paul
Top achievements
Rank 1
answered on 16 Feb 2018, 04:38 PM

Okay, I'm still having issues with this.

How do I create my own X axis labels if I know the start date/time and end date/time and the number of ticks between?

Is there an example of how to do this?

Paul

 

0
Martin Ivanov
Telerik team
answered on 21 Feb 2018, 09:20 AM
Hello Paul,

There is no example how to create custom labels with annotations. However, I prepared a small example showing this and attached it here. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ChartView
Asked by
Paul
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Paul
Top achievements
Rank 1
Share this question
or