Problem exporting databound chart that isn't visible

8 posts, 0 answers
  1. David Brubacher
    David Brubacher avatar
    29 posts
    Member since:
    Mar 2010

    Posted 20 Aug 2010 Link to this post

    As part of my application I am storing some meta-data on the server. That meta-data needs to contain a chart.
    I have a user control that contains all of the logic of the chart, which the user can see at any time just by clicking a button.

    I'm trying to generate the same chart and export it to a PNG even if the chart isn't visible
            /// <summary>
            /// Send a chart image when asked
            /// </summary>
            public byte[] MakeChartImage()
            {
                chart.Arrange(new Rect(new Point(0, 0), new Size(1024, 768)));
                var stream = new MemoryStream();
                chart.ExportToImage(stream, new PngBitmapEncoder());
                return stream.ToArray();
           }

    I'm using MEF and MVVM, so the cart gets a message that there is new chart data, does a Rebind, then
    raises an event to let the calling app know its safe to call the above method.

    The chart I get is devoid of all bound data (see attachment).
    How do you force the chart to render despite it not being visible?
    I've also included a chart as it looks when the user views it.


  2. David Brubacher
    David Brubacher avatar
    29 posts
    Member since:
    Mar 2010

    Posted 20 Aug 2010 Link to this post

    This is what the chart should look like (minus the radwindow)
  3. DevCraft banner
  4. David Brubacher
    David Brubacher avatar
    29 posts
    Member since:
    Mar 2010

    Posted 20 Aug 2010 Link to this post

    Some progress.

    Here is where I generate the meta-data in a view model
            /// <summary>
            /// Report metadata back to the server on what we are querying
            /// </summary>
            /// <param name="ignore">This value isn't used</param>
            private void GenerateData(string ignore)
            {
                var chart = new ChartView();
                chart.DataBound += ChartDataBound;
                _ChartWindow = new RadWindow
                                   {
                                       Left = -2000,
                                       Top = -2000,
                                       Width = 1100,
                                       Height = 850,
                                       Content = chart
                                   };
                _ChartWindow.Show();
                SendDataToChart(false);
            }

            private void ChartDataBound(object sender, EventArgs e)
            {
                var chart = sender as ChartView;
                if (chart == null)
                {
                    _ChartWindow.Close();
                    return;
                }
                var usage = new Usage
                {
                    ...,
                    Chart = chart.MakeChartImage(),
                    ...,
                };
                _ChartWindow.Close();
                _Model.SubmitUsage(usage);
            }


    and here is the MakeChartImage() method
            /// <summary>
            /// Send a chart image when asked
            /// </summary>
            public byte[] MakeChartImage()
            {
                chart.UpdateLayout();
                var stream = new MemoryStream();
                chart.ExportToImage(stream, new PngBitmapEncoder());
                return stream.ToArray();
            }
    The some data it binding but not the bubbles
  5. Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 25 Aug 2010 Link to this post

    Hello David,

    Try disabling the chart animations (RadChart.DefaultView.ChartArea.EnableAnimations = false) prior to exporting the image and you should be able to achieve the desired effect.


    Greetings,
    Bart.
  6. David Brubacher
    David Brubacher avatar
    29 posts
    Member since:
    Mar 2010

    Posted 25 Aug 2010 Link to this post

    No change unfortunately. Thanks for the suggestion though.
  7. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 26 Aug 2010 Link to this post

    Hello David,

    Based on the supplied information, it is hard to determine what is causing this unwanted behavior. If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your implementation, and showing the unwanted behavior. We will review it locally, and advise you further.

    All the best,
    Yavor
    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
  8. David Brubacher
    David Brubacher avatar
    29 posts
    Member since:
    Mar 2010

    Posted 29 Sep 2010 Link to this post

    Sorry for not supplying additional info - circumstances took me away from this project for a while.
    I've returned to it today, applied the new service pack and voila! everything works as expected.

    Thnk-you very much!
  9. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 04 Oct 2010 Link to this post

    Hi David,

    I am glad that the issue has been resolved, and that the project is working as per your requirements now.
    If further questions/issues arise, let us know.

    Regards,
    Yavor
    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