Programmatically create Horizontal Stacked Bar

4 posts, 0 answers
  1. Tony
    Tony avatar
    12 posts
    Member since:
    Jul 2015

    Posted 26 Aug 2015 Link to this post

    Hi All,

    I am trying to create a horizontal stacked bar to show data.  Below is the code I have so far.

     

    The problems that I'm having are:

    1.  It creates the chart but the data bar seems to be vertical.  I want it to go horizontal.

    2.  I want each segment of the bar to have a different color automatically from the theme.

    3.  I want each segment of the bar to have its own tooltip.

     What am I missing?

    Thanks for your help!     

     

     this.Chart = new Telerik.Windows.Controls.RadCartesianChart() {
                    MinHeight = 0,
                    MinWidth = 0,
                    HorizontalAxis = new Telerik.Windows.Controls.ChartView.CategoricalAxis() {
                        Visibility = System.Windows.Visibility.Collapsed,
                    },
                    VerticalAxis = new Telerik.Windows.Controls.ChartView.LinearAxis() {
                        Visibility = System.Windows.Visibility.Collapsed,
                    }
                };

                Chart.Background = System.Windows.Media.Brushes.Green;

                Chart.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                Chart.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

                var DataSeries = new Telerik.Windows.Controls.ChartView.BarSeries();
                DataSeries.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack100;

                foreach (var item in e.Parameters) {
                    DataSeries.DataPoints.Add(new Telerik.Charting.CategoricalDataPoint() { Value = item.Used, Category = "1" });
                    DataSeries.DataPoints.Add(new Telerik.Charting.CategoricalDataPoint() { Value = item.Available, Category = "1" });
                }

                Chart.Series.Add(DataSeries);​

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 26 Aug 2015 Link to this post

    Hello Tony,

    To create horizontal bar chart you can just swap the values of the VerticalAxis and HorizontalAxis property of the chart.
    HorizontalAxis = new Telerik.Windows.Controls.ChartView.LinearAxis() {
        Visibility = System.Windows.Visibility.Collapsed,
    },
    VerticalAxis = new Telerik.Windows.Controls.ChartView.CategoricalAxis() {
        Visibility = System.Windows.Visibility.Collapsed,
    },

    RadChartView doesn't have different design for the different themes, however, it supports palettes which you can use to draw the data points in different colors.
    this.Chart.Palette = ChartPalettes.Windows8;

    To add a tooltip for each chart data point (each segment of the bar) you can use the ChartTooltipBehavior.

    Please let me know if this information is useful.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tony
    Tony avatar
    12 posts
    Member since:
    Jul 2015

    Posted 27 Aug 2015 in reply to Martin Link to this post

    Hi Martin,

    Thank you for the information.  This helped!  Regarding the palette -

    Is there a way to make the chart "inherit" from the theme that I've set for the application?  I would like changing the theme to automatically change the palette as well.

     Thanks!     

  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 01 Sep 2015 Link to this post

    Hello Tony,

    RadChartView doesn't support automatically changing of its Palette based on the applied theme. In order to achieve this you will need to manually set the palette when the theme is changed. 

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top