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

Adding another serie dynamically

5 Answers 124 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Chris Thierry
Top achievements
Rank 1
Chris Thierry asked on 03 Aug 2010, 04:02 PM
Hi, I'm creating a barseriesdefinition in a chart like this when I load the page:

                SeriesMapping seriesMapping = new SeriesMapping();
                seriesMapping.SeriesDefinition = new BarSeriesDefinition();

                
                //Fill Serie with Provider color
                if (_item_index != -1)
                {
                    seriesMapping.SeriesDefinition.Appearance.Fill = chart_Provider.PaletteBrushes[_item_index % 10];
                    _item_index = -1;
                }
                ItemMapping yMapping = new ItemMapping("quantity", DataPointMember.YValue);
                ItemMapping catMapping = new ItemMapping("period", DataPointMember.XCategory);

                
                seriesMapping.ItemMappings.Add(yMapping);
                seriesMapping.ItemMappings.Add(catMapping);

                
                chart_Months.SeriesMappings.Add(seriesMapping);

                chart_Months.ItemsSource = e.Result.ToList();

after that, if the user click in a list that I have in my page, I'm adding a new SplineSeriesDefinition to the existing graph, so I'm doing this calling to another WCF service:

    SeriesMapping seriesMapping = new SeriesMapping();

    seriesMapping.SeriesDefinition =

 

new SplineSeriesDefinition();

 

    ItemMapping yMapping = new ItemMapping("quantity", DataPointMember.YValue);

    ItemMapping catMapping = new ItemMapping("period", DataPointMember.XCategory);

 

    seriesMapping.ItemMappings.Add(yMapping);

    seriesMapping.ItemMappings.Add(catMapping);

    chart_Months.SeriesMappings.Add(seriesMapping);

I'm doing something wrong with the series because the second series shows me the same values of the first one. My first series has for example cost grouped by a, b and c, my second serie shows only cost grouped by a. I can´t load everything and then hide a serie because I don't know wich one is going to be selected

Could you please tells me how to do this?

 

By the way, I'm using a PaletteBrushes for my first serie, if I'm generating my second serie, sometimes depending on the color is using the same color for both series, is there any way to avoid this?
Thank you very much

5 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 06 Aug 2010, 02:05 PM
Hello Chris,

Both of your series are defined by identical ItemMappings (use quantity field for YValue and period for XCategory) and that is why they will always display identical data -- probably you want to map different field for the YValue in the second series or we are missing something out?

As for your second question -- we were unable to reproduce the problematic behavior with the PaletteBrushes. Could you open a formal support ticket and send us a sample runnable application that we can investigate locally?

Looking forward to your reply.


Regards,
Freddie
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Chris Thierry
Top achievements
Rank 1
answered on 06 Aug 2010, 02:39 PM
of course I'm using the same names (quantity and period) because I'm getting the information from the same stored procedure with different parameters, do I need to create another stored procedure that returns different names?

For the PaletteBrushes,  when I'm loading my secound serie, is using a color that I already have in my first serie, I can't send you all the project.

This is how is working: first I have a pie char of providers with a PaletteBrushes defined manually (10 colors), if the user click in one provider, I'm showing in another bar chart total charges by months. The reason by I am using the palette is because in my second chart I am using the same color that represents the selected provider. For example, if the provider selected has a red color, in my second chart, the color will be red.
After that, I'm adding in my second chart another serie (line serie), when I'm doing that, the color selected by telerik is red, so, I have two reds in my chart, how can I tell the object to use another color than red?, should I use the same palette that I'm using for providers?

Looking forward to your reply
Thanks
 
I tried to use different names for quantity and period, but as soon as I change my Itemsource, is representing my second chart and my first chart is gone, I need to show two series but one after the other and is not at the same time, I explained this case in my first email.

Should I open a ticket? because I didn't have an answer yet.
Thank you.
0
Giuseppe
Telerik team
answered on 11 Aug 2010, 11:59 AM
Hi Chris,

As noted in your support ticket, RadChart does not support setting itemssource per series level and you will need to use binding to nested collection in order to achieve the desired effect (the ItemsSource should be set to the nested collection itself and each service result should be added to the nested collection and associated with its respective series via SeriesMapping.CollectionIndex).

As for the PaletteBrushes -- my colleague Ves already explained in different support ticket that RadChart does not provide such inter-control styles sync, so you will have to do it manually. When clicking in the pie chart, find the index of the item clicked and retrieve the corresponding brush in the PaletteBrushes collection. Then you can add it to the PaletteBrushes of the second chart -- this way the second chart's PaletteBrushes will always contain the brushes of the clicked items in the first one, in the order they were clicked. Alternatively, you can use the Appearance API (SeriesDefinition.Appearance complex property) as well -- when you click in the pie chart, you know the item index thus you know desired series color and you can manually set SeriesDefinition.Appearance.Fill for the chart series in the second chart.

Hope this helps.


Regards,
Freddie
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Chris Thierry
Top achievements
Rank 1
answered on 11 Aug 2010, 05:23 PM
Hi,
I was checking Data Binding to Nested Collections to resolve my problem, what I saw in the example is that the item source is used after filling both seriesMapping.CollectionIndex IN THE SAME METHOD, but as I explained before, I don´t want to create the first series again because is already in my page, I only need to add my second serie but not at the same time because I don't know how is going to look my second chart.

Do you please have and example?
Thank you.
0
Giuseppe
Telerik team
answered on 13 Aug 2010, 12:57 PM
Hi Chris Thierry,

RadChart does not support such partial rendering / preserving rendered series -- whenever you add new series mapping, the control will rebind itself completely i.e. each time the rebind / redraw logic will be executed for all series mappings added to the RadChart.SeriesMappings collection and not only for the new mapping.


All the best,
Freddie
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Chris Thierry
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Chris Thierry
Top achievements
Rank 1
Share this question
or