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

RadChartView not showing bars when saved to file

4 Answers 194 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
dd
Top achievements
Rank 1
dd asked on 04 Mar 2013, 08:09 PM
I have noticed some strange behavior when I try to save a chart as an image.  The x and y axis show up with labels and the correct range but there are no bars.

    Private Function GetDummyList() As BindingList(Of RateShockData)
        Dim l As New BindingList(Of RateShockData)
        l.Add(New RateShockData("+300", "-13.9"))
        l.Add(New RateShockData("+200", "-9"))
        l.Add(New RateShockData("+100", "-3.9"))
        l.Add(New RateShockData("even", "0"))
        l.Add(New RateShockData("-100", "-.2"))
        l.Add(New RateShockData("-200", "1"))
        l.Add(New RateShockData("-300", "2.2"))
        Return l
    End Function
 
    Private Function BuildChart()
        Dim c1 As New RadChartView
 
        Dim bs As New BarSeries
        bs.Name = "Market % Change"
        bs.ValueMember = "MVPctChange"
        bs.CategoryMember = "BPChange"
        bs.DataSource = GetDummyList()
 
        c1.Series.Clear()
        c1.Series.Add(bs)
 
        Dim bitM As New Bitmap(c1.Width, c1.Height)
        c1.DrawToBitmap(bitM, c1.Bounds)
 
        Dim imageFileName As String = Guid.NewGuid.ToString + ".jpg"
        bitM.Save(imageFileName, Drawing.Imaging.ImageFormat.Jpeg)
    End Function
 
    Private Sub RadButton2_Click(sender As Object, e As EventArgs) Handles RadButton2.Click
        BuildChart()
 
    End Sub
 
 
Public Class RateShockData
 
    Property BPChange As String
    Property MVPctChange As String
 
    Public Sub New(bpc As String, mvpc As String)
        BPChange = bpc
        MVPctChange = mvpc
    End Sub
 
End Class

The above code is what I used to produce this.  I am using version 2012.2.726.40.

I discovered that if I give the chart a palette, this issue goes away.

c1.Area.View.Palette = KnownPalette.Grayscale

4 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 07 Mar 2013, 03:59 PM
Hello David,

Thank you for writing.

The reason why the bars do not have a style is because we use animations when we apply the theme. The animations fades in the colors and in your case the animation has just started when you draw the control to the bitmap. To workaround this you can disable the animations. Here is how to modify your code:
Private Function BuildChart()
        ThemeResolutionService.AllowAnimations = False
 
        Dim c1 As New RadChartView
  
        Dim bs As New BarSeries
        bs.Name = "Market % Change"
        bs.ValueMember = "MVPctChange"
        bs.CategoryMember = "BPChange"
        bs.DataSource = GetDummyList()
  
        c1.Series.Add(bs)
  
        Dim bitM As New Bitmap(c1.Width, c1.Height)
        c1.DrawToBitmap(bitM, c1.Bounds)
  
        Dim imageFileName As String = Guid.NewGuid.ToString + ".jpg"
        bitM.Save(imageFileName, Drawing.Imaging.ImageFormat.Jpeg)
    End Function

I hope this will help. Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Michael
Top achievements
Rank 1
answered on 15 Aug 2013, 07:40 PM
Ivan,

The (ThemeResolutionService.AllowAnimations = False. ) solution worked great for a barseries within the RadChartView when not within a visual form. However the same does not seem to work when using the pieseries. The only way in which I can get the pie chart to draw and paint the pie is to give it a known palette. Is there another solution in this case?

What is the default palette of the chart when in a pieseries mode?

Thanks

Mike C.
0
Michael
Top achievements
Rank 1
answered on 16 Aug 2013, 01:54 AM
Ivan,

I was able to stop loading a known palette within the radchartview and get the pie chart to draw within a bitmap by calling the LoadElementTree of the radchartview. The bitmap now displays the pie chart, however I no longer get the Legend to draw. Prior to using the LoadElementTree method the legend was drawn within the bitmap , however I was not able to loop through the legend items to modify them in any manner as the count indicated 0.

After calling the LoadElementTree method I can loop through the Legend Items as the count now indicates non zero. The legend simply no longer draws within the bitmap


Thanks

Mike C
0
Ivan Petrov
Telerik team
answered on 20 Aug 2013, 11:42 AM
Hello David,

Thank you for writing back.

The best way to get a control to look as it would normally do is to put it in its "natural environment". You can add a control to a form Controls collection, force a layout, draw it to a bitmap and remove it. This will not be drawn in the UI as it will happen pretty fast but will allow all the mechanism in the control to function properly.

I have attached an example project with two buttons, one exports the bar chart from your first post with legend and the second exports a pie chart again with a legend.

I hope this will be useful. Feel free to write back with further questions.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
ChartView
Asked by
dd
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Michael
Top achievements
Rank 1
Share this question
or