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

StackedBarSeriesDefinition doesn't change to CandleStickSeriesDefinition

5 Answers 134 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hakki
Top achievements
Rank 1
Hakki asked on 18 Sep 2012, 11:44 AM
Hello,

I am presenting categorical and numerical data. Categorical with Stacked Bar, numerical with Candle Stick.

So if is categorical, show Stacked Bar chart:
MyRadChart.DefaultView.ChartLegend.Visibility = Visibility.Visible;
                                MyRadChart.DefaultView.ChartArea.AxisX.Title = "Visit";
 
                                MyRadChart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;
 
                                var seriesMappingCat = new SeriesMapping
                                    {SeriesDefinition = new StackedBarSeriesDefinition {ShowItemLabels = false}};
 
                                seriesMappingCat.ItemMappings.Add(new ItemMapping("ValidTextColumn",
                                                                               DataPointMember.YValue));
                                seriesMappingCat.ItemMappings.Add(new ItemMapping("VisitColumn", DataPointMember.XCategory));
 
                                MyRadChart.DefaultView.ChartArea.AxisY.AutoRange = false;
                                MyRadChart.DefaultView.ChartArea.AxisY.Step = 1;
 
                                MyRadChart.SeriesMappings.Add(seriesMappingCat);

If numerical, Candlestick chart:

MyRadChart.DefaultView.ChartLegend.Visibility = Visibility.Collapsed;
                           MyRadChart.DefaultView.ChartArea.AxisX.Title = "Visit";
 
                           var seriesMappingNum = new SeriesMapping
                               {SeriesDefinition = new CandleStickSeriesDefinition {ShowItemLabels = false}};
 
                           seriesMappingNum.ItemMappings.Add(new ItemMapping("VisitColumn", DataPointMember.XCategory));
                           seriesMappingNum.ItemMappings.Add(new ItemMapping("Q1Column", DataPointMember.Open));
                           seriesMappingNum.ItemMappings.Add(new ItemMapping("Q3Column", DataPointMember.Close));
                           seriesMappingNum.ItemMappings.Add(new ItemMapping("MinColumn", DataPointMember.Low));
                           seriesMappingNum.ItemMappings.Add(new ItemMapping("MaxColumn", DataPointMember.High));
 
                           MyRadChart.SeriesMappings.Add(seriesMappingNum);

If I select candle stick first then switch to stacked bar, it works but if I select stacked bar first, then switch to candle stick, the candle stick chart doesn't draw.

I have debugged to make sure the data is going through correctly and data is consistently correct, it just doesn't draw.

Thanks for any help.

5 Answers, 1 is accepted

Sort by
0
Hakki
Top achievements
Rank 1
answered on 18 Sep 2012, 02:31 PM
I was using the Metro theme. It worked with the default.
0
Petar Marchev
Telerik team
answered on 21 Sep 2012, 08:47 AM
Hi Hakki,

Thank you for the attached code snippets. I created a new project based on it and did some testing. Indeed I can confirm the presence of this faulty behavior when I used the code you have attached. However I spotted an incompatibility and after removing it the glitch is not present any more.
MyRadChart.DefaultView.ChartArea.AxisY.AutoRange = false;
MyRadChart.DefaultView.ChartArea.AxisY.Step = 1;

Remove these two lines and it should work just fine. The reason for this buggy behavior is that you set the axis into manual mode, but then you don't specify a min and max, only step. So the chart cannot get a min and max from your items source and it is puzzled with what to show - so it tries to show something, but doesn't work out very well. So the solution is to simply always use the axis in auto-range mode.

Let us know if you can update your project to always use the axis in its auto mode. I have attached the app I tested with.

Kind regards,
Petar Marchev
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Hakki
Top achievements
Rank 1
answered on 21 Sep 2012, 09:07 AM
double post, see below
0
Hakki
Top achievements
Rank 1
answered on 21 Sep 2012, 09:11 AM
That makes sense but it was odd how the exact code I pasted in the first post worked with the default theme and not with Metro. That's what had me so puzzled.

I am now using the Summer theme and am defining axisy.maxvalue and axisy.step and can switch between two charts with no problem. It works with all other themes by the way, I picked summer simply because I liked it most.

And for clarity here is the code for Stack:

//set up X-axis of chart as visit
MyRadChart.DefaultView.ChartLegend.Visibility = Visibility.Visible;
MyRadChart.DefaultView.ChartArea.AxisX.Title = "Visit";
 
//for each column, set up series
for (var sm = 0; sm < Phpdata.ColumnCount; sm++)
{
    var seriesMappingCat = new SeriesMapping
        {
            SeriesDefinition = new StackedBarSeriesDefinition {ShowItemLabels = false},
            LegendLabel = RadGrid.Columns["PercentColumn" + sm].Header.ToString()
        };
 
    seriesMappingCat.ItemMappings.Add(new ItemMapping("PercentageColumn",
                                                      DataPointMember.YValue));
    seriesMappingCat.ItemMappings.Add(new ItemMapping("VisitColumn",
                                                      DataPointMember.XCategory));
         
    //set display options
    MyRadChart.DefaultView.ChartArea.AxisY.AutoRange = false;
    MyRadChart.DefaultView.ChartArea.AxisY.MaxValue = 100;
    MyRadChart.DefaultView.ChartArea.AxisY.Step = 10;
 
    //complete
    MyRadChart.SeriesMappings.Add(seriesMappingCat);
 
}
   

And candle stick:

MyRadChart.DefaultView.ChartLegend.Visibility = Visibility.Collapsed;
                        MyRadChart.DefaultView.ChartArea.AxisX.Title = "Visit";
 
                        var seriesMappingNum = new SeriesMapping
                            {
                                SeriesDefinition = new CandleStickSeriesDefinition { ShowItemLabels = false, }
                            };
 
                        seriesMappingNum.ItemMappings.Add(new ItemMapping("VisitColumn", DataPointMember.XCategory));
                        seriesMappingNum.ItemMappings.Add(new ItemMapping("Q1Column", DataPointMember.Open));
                        seriesMappingNum.ItemMappings.Add(new ItemMapping("Q3Column", DataPointMember.Close));
                        seriesMappingNum.ItemMappings.Add(new ItemMapping("MinColumn", DataPointMember.Low));
                        seriesMappingNum.ItemMappings.Add(new ItemMapping("MaxColumn", DataPointMember.High));
 
                        seriesMappingNum.SeriesDefinition.Appearance.Fill = new SolidColorBrush(Colors.Red) {Opacity = 5};
                        seriesMappingNum.SeriesDefinition.Appearance.Stroke = new SolidColorBrush(Colors.Red);
 
                        MyRadChart.SeriesMappings.Add(seriesMappingNum);
0
Petar Kirov
Telerik team
answered on 26 Sep 2012, 08:44 AM
Hello Hakki,

It is rather strange that you have observed different behaviour with our series, by changing the theme. We couldn't reproduce the unwanted behaviour on our side.  We tested this in the attached project from the previous post by uncommenting the troublesome code segment and changing the theme by using the StyleManager.

If you still experience issues caused by changing the theme, we would appreciate if you report those problems (together with your runnable sample project which reproduces them) to us so we can investigate them locally.
 
All the best,
Petar Kirov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Tags
Chart
Asked by
Hakki
Top achievements
Rank 1
Answers by
Hakki
Top achievements
Rank 1
Petar Marchev
Telerik team
Petar Kirov
Telerik team
Share this question
or