Horizontal axis inside a chart area

3 posts, 1 answers
  1. Sergei
    Sergei avatar
    2 posts
    Member since:
    May 2016

    Posted 24 May Link to this post

    Hello,

    I need to display categorical X axis at Y=0 point, like on the picture. If 0 is out of Y axis range, X axis should be displayed at the bottom as by default. There is a CategoricalAxis.VerticalLocation property but it has only Top and Bottom options.

    I shifted the axis manually using TranslateTransform for the example. But I need XAML to be independent on data source.

                                <telerik:RadCartesianChart.HorizontalAxis>
                                    <telerik:CategoricalAxis PlotMode="OnTicksPadded" LabelFitMode="MultiLine">
                                        <chartview:CategoricalAxis.RenderTransform>
                                            <TranslateTransform Y="-149"/>
                                        </chartview:CategoricalAxis.RenderTransform>
                                    </telerik:CategoricalAxis>
                                </telerik:RadCartesianChart.HorizontalAxis>

    Are there any ways how to do it?

    Thanks,

    Sergei

  2. Answer
    Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 25 May Link to this post

    Hello,

    The ChartView control does not support changing the origin position of the axes. The horizontal axis can be positioned at the top or bottom of the plot area. However, you can achieve your requirement using  annotations. Basically, by doing the following:
    • Define BarSeries and populate its ItemsSource with your data.
    • Hide the vertical axis of the chart by setting its ElementBrush property to Transparent. This will hide the ticks, labels and the axis' line.
    • Define a CartesianGridLineAnnotation and position it at value 0. This line will represent the axis.
    • Define CartesianCustomAnnotations which will present the labels of the annotation used as an axis. To do so you can subscribe for the Loaded event of the series. If you have a data bound scenario you can use the series' DataBindingCompleted event instead of Loaded. Then in the event handler you can get the categorical axis' categories using its Categories property and based on it create the annotations.
    Attached is a sample project demonstrating this approach.

    Hope it helps.


    Regards,
    Peshito
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Sergei
    Sergei avatar
    2 posts
    Member since:
    May 2016

    Posted 26 May in reply to Peshito Link to this post

    Thank you Peshito.

    Unfortunately I can't use "smart labels" in this way. But you helped me to get an idea to combine CustomAnnotation and VisualBrush.

    Thanks a lot!

    Sergei

Back to Top