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

Programmatically create Horizontal Stacked Bar

3 Answers 204 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 26 Aug 2015, 03:13 PM

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);​

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 26 Aug 2015, 04:19 PM
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
0
Tony
Top achievements
Rank 1
answered on 27 Aug 2015, 09:02 PM

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!     

0
Martin Ivanov
Telerik team
answered on 01 Sep 2015, 08:24 AM
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
Tags
ChartView
Asked by
Tony
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Tony
Top achievements
Rank 1
Share this question
or