Adding another serie dynamically

6 posts, 0 answers
  1. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 03 Aug 2010 Link to this post

    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

  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 06 Aug 2010 Link to this post

    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
  3. DevCraft banner
  4. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 06 Aug 2010 Link to this post

    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.
  5. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 11 Aug 2010 Link to this post

    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
  6. Chris Thierry
    Chris Thierry avatar
    138 posts
    Member since:
    Jun 2010

    Posted 11 Aug 2010 Link to this post

    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.
  7. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 13 Aug 2010 Link to this post

    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
Back to Top
DevCraft banner