Printing Bar Chart

9 posts, 0 answers
  1. jay
    jay avatar
    10 posts
    Member since:
    Mar 2011

    Posted 08 Mar 2011 Link to this post

    Need some help with this.  I've been able to print line charts, however I'm now adding a Bar Chart to the mix and can't get it to print.  The only output I get are the labels, so that I know I'm getting data back and that it's not rendering correctly.  I've attached an image of what I'm able to get to print and here is the code:

    RadChart rptRevenueChart = new RadChart(); 
    rptRevenueChart.DefaultView.ChartArea.EnableAnimations = false
    SeriesMapping smRewards = new SeriesMapping(); 
    smRewards.LegendLabel = "Rewards"
    StackedBarSeriesDefinition sd1 = new StackedBarSeriesDefinition(); 
    smRewards.SeriesDefinition = sd1; 
    smRewards.ItemMappings.Add(new ItemMapping("RewardAmount", DataPointMember.YValue)); 
    rptRevenueChart.SeriesMappings.Add(smRewards); 
    rptRevenueChart.ItemsSource = RevenueChartData;


    I then set the pagevisual and to the grid and print.  This works for other elements (charts) on the page just fine, it's just the bar chart that I'm fighting with right now.  Thoughts?

    Jay Hammett
    Developer

  2. jay
    jay avatar
    10 posts
    Member since:
    Mar 2011

    Posted 08 Mar 2011 Link to this post

    Ok, I have since edited my code to include the data and get the same results, meaning just the bar label NOT the actual bar itself.  Here's the current code:

    RadChart rptRevenueChart = new RadChart();
      
    List<Company> sampleData = new List<Company>(); 
    sampleData.Add(new Company("AAA", 500)); 
    sampleData.Add(new Company("BBB", 600)); 
    sampleData.Add(new Company("CCC", 100)); 
    sampleData.Add(new Company("DDD", 100)); 
    sampleData.Add(new Company("EEE", 300)); 
    sampleData.Add(new Company("FFF", 200)); 
    sampleData.Add(new Company("GGG", 900)); 
    sampleData.Add(new Company("HHH", 400)); 
    sampleData.Add(new Company("III", 400)); 
    sampleData.Add(new Company("JJJ", 200));
      
    SeriesMapping smRewards = new SeriesMapping();
      
    BarSeriesDefinition sd1 = new BarSeriesDefinition();
      
    smRewards.SeriesDefinition = sd1;
      
    smRewards.ItemMappings.Add(new ItemMapping("Value2", DataPointMember.YValue));
      
    rptRevenueChart.SeriesMappings.Add(smRewards);
    rptRevenueChart.DefaultView.ChartArea.EnableAnimations = false;
    rptRevenueChart.ItemsSource = sampleData;
  3. jay
    jay avatar
    10 posts
    Member since:
    Mar 2011

    Posted 08 Mar 2011 Link to this post

    Here's the printed image from the above code.  Please note the absence of bars...
  4. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 09 Mar 2011 Link to this post

    Hello jay,

    Indeed currently there is a problem with the print/export bar series type in this scenario and you will need to apply this custom bar style manually (it explicitly sets the Opacity to 1):
    Copy Code
    Copy Code
    Copy Code
    <Style x:Key="PrintStyle" TargetType="telerik:Bar">
        <Setter Property="Template" >
            <Setter.Value>
                <ControlTemplate TargetType="telerik:Bar">
                    <Canvas Opacity="1" x:Name="PART_MainContainer">
                        <Rectangle x:Name="PART_DefiningGeometry"                                   
                                    Height="{TemplateBinding ItemActualHeight}"
                                    Width="{TemplateBinding ItemActualWidth}"
                                    Style="{TemplateBinding ItemStyle}"
                                    RadiusX="{StaticResource BarRadiusX}"
                                    RadiusY="{StaticResource BarRadiusY}" />
                        <Rectangle Height="{TemplateBinding ItemActualHeight}"
                                    Width="{TemplateBinding ItemActualWidth}"
                                    RadiusX="{StaticResource BarMaskRadius}"
                                    RadiusY="{StaticResource BarMaskRadius}"
                                    OpacityMask="{StaticResource BarOpacityMaskBrush}"
                                    Fill="{StaticResource BarMaskBrush}"
                                    Stroke="{StaticResource BarMaskStroke}"
                                    StrokeThickness="{StaticResource BarMaskStrokeThickness}" />
                        <Rectangle x:Name="PART_SelectedState"
                                    Height="{TemplateBinding ItemActualHeight}"
                                    Width="{TemplateBinding ItemActualWidth}"
                                    RadiusX="{StaticResource BarRadiusX}"
                                    RadiusY="{StaticResource BarRadiusY}"
                                    Fill="{StaticResource BarTopMaskBrush}" />
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    We have attached a sample application as well.


    Regards,
    Giuseppe
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  5. jay
    jay avatar
    10 posts
    Member since:
    Mar 2011

    Posted 09 Mar 2011 Link to this post

    Would you have an example of building the style in a MVVM scenario from code vs. in the .xaml file?  The entire chart is created and printed from code and there is no access to the view where a xaml style template would be.
  6. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 10 Mar 2011 Link to this post

    Hi jay,

    In such case you would need to move the style to the code and parse it through XamlReader.Load(...) -- see modified sample application that achieves the desired effect entirely from code behind.


    Greetings,
    Giuseppe
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  7. jay
    jay avatar
    10 posts
    Member since:
    Mar 2011

    Posted 10 Mar 2011 Link to this post

    The style worked!  Thanks.  I was able to include it as a resource in the view xaml and then reference the resource from the view model.
  8. Gary
    Gary avatar
    7 posts
    Member since:
    May 2011

    Posted 01 Jun 2011 Link to this post

    I will try this on my bar graph, but I am also experiencing this issue with stack bars. Everything is fine when I write to windows xps but when I when I print to an actual printer, the bars and stack bars disappear. Also all my legends become horizontal oriented when they should be vertical.
  9. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 06 Jun 2011 Link to this post

    Hi Gary,

    The approach described in the previous posts should work for stacked bar series as well as the style for both series is identical.

    If the problem persists, we would ask you to open a formal support ticket and send us a runnable version of your application that we can investigate locally so we can advise you properly how to proceed.


    Greetings,
    Giuseppe
    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