Chart view image doesn't work correctly

5 posts, 1 answers
  1. Mathieu
    Mathieu avatar
    6 posts
    Member since:
    Feb 2014

    Posted 02 Sep 2015 Link to this post

    Hi,

    I'm facing a strange behaviour when i export a userControl containing a ChartView as a png picture.
    Let's explain my issue with code.

    First i create a userControl, this userControl has a title ( label) and a chartView.

    this chart is slightly customized, i want to show checkboxes as legend items. to do this, i have followed an example mentioned in the forum.

    If the checkbox is unckeced the related serie is hidden.

     

    var myUserControl = new StatisticLayoutWithAdditionalStats();
     
    myUserControl.ChartView.ChartElement.LegendElement.VisualItemCreating += LegendElement_VisualItemCreating;
    /// Set layout properties
    myUserControl.Title = "Blablabla";
    myUserControl.ChartView.AreaType = ChartAreaType.Cartesian;
    myUserControl.ChartView.ShowLegend = true;
     
    LineSeries serie1 = new LineSeries();
    LineSeries serie2 = new LineSeries();
     
     
    serie1.DataSource = new BindingList<Coordinate>(Serie1DataSource.Coordinates);
    serie1.CategoryMember = "Abscissa";
     
    serie2.DataSource = new BindingList<Coordinate>(Serie2DataSource.Coordinates);
    serie2.CategoryMember = "Abscissa";
    serie2.ValueMember = "Ordinate";
     
    myUserControl.ChartView.Series.Add(serie1);
    myUserControl.ChartView.Series.Add(serie2);

     

    // This class is used to customize legend items
    public class CheckBoxLegentItemElement : LegendItemElement
    {
     private RadCheckBoxElement checkBox = new RadCheckBoxElement();
     
    public CheckBoxLegentItemElement(LegendItem item)
    {
     this.checkBox.ToggleStateChanged += checkBox_ToggleStateChanged;
    }
     
     void checkBox_ToggleStateChanged(object sender, StateChangedEventArgs args)
            {
                if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
                {
                    this.LegendItem.Element.IsVisible = true;
                }
                else
                {
                    this.LegendItem.Element.IsVisible = false;
     
                }
            }
     
     
    }

     

    If i display this userControl in a Form it works fine.

    But i want to export this userControl as a picture, the userControl can't be displayed in a form, juste created in memory.

     

    myUserControl.Size = new Size(600,400);
    Bitmap bitmap = new Bitmap(600, 400);
    myUserControl.DrawToBitmap(bitmap, (myUserControl.ClientRectangle));

    If all checkboxes are checked, the image is good.

    But if, at least, one of them is uncheck the graph doesn't display.

    Do you have any explanation ?

    Regards,

    Mathieu

  2. Answer
    Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 03 Sep 2015 Link to this post

    Hi Mathieu,

    Thank you for writing.

    Your implementation of the custom LegendItemElement also needs an override of the CreateChildElements method where you would need to add the RadCheckBoxElement to the CheckBoxLegentItemElement.Children collection.

    I further extended the sample code you provided. In my project, I am also using an in memory user control and the chart exports to image successfully whether all of the checkboxes are checked or not. Besides the project, I am also sending you a screenshot of the exported image.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    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 WinForms is Visual Studio 2017 Ready
  4. Mathieu
    Mathieu avatar
    6 posts
    Member since:
    Feb 2014

    Posted 03 Sep 2015 in reply to Hristo Link to this post

    Hi Hristo,

    Thank you for you reply.

    I launched your attached example but in don't have the same result : the exported image is not displayed.

  5. Mathieu
    Mathieu avatar
    6 posts
    Member since:
    Feb 2014

    Posted 03 Sep 2015 in reply to Mathieu Link to this post

    Hi Hristo, 

    I found the issue, we didn't upgrade our dll version.

    It works fine with the latest ones.

     

    Thank you very much for your help.

     

    Mathieu

  6. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 08 Sep 2015 Link to this post

    Hello Mathieu,

    Thank you for writing back.

    I am glad that you have resolved your issue. Please note that in forum threads, unless explicitly specified by you, we are assuming that latest version is being used.

    We have recently introduced many improvements and new features in RadChartView and by updating your controls you would benefit from them all. You can check the following blog posts, providing information of the newly implemented functionality:
     I hope this information is useful. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    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
UI for WinForms is Visual Studio 2017 Ready