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

Printing Bar Chart

8 Answers 103 Views
Chart
This is a migrated thread and some comments may be shown as answers.
jay
Top achievements
Rank 1
jay asked on 08 Mar 2011, 05:08 PM
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

8 Answers, 1 is accepted

Sort by
0
jay
Top achievements
Rank 1
answered on 08 Mar 2011, 08:47 PM
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;
0
jay
Top achievements
Rank 1
answered on 08 Mar 2011, 10:45 PM
Here's the printed image from the above code.  Please note the absence of bars...
0
Giuseppe
Telerik team
answered on 09 Mar 2011, 11:13 AM
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!
0
jay
Top achievements
Rank 1
answered on 09 Mar 2011, 04:08 PM
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.
0
Giuseppe
Telerik team
answered on 10 Mar 2011, 10:26 AM
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!
0
jay
Top achievements
Rank 1
answered on 10 Mar 2011, 06:32 PM
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.
0
Gary
Top achievements
Rank 1
answered on 01 Jun 2011, 10:52 PM
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.
0
Giuseppe
Telerik team
answered on 06 Jun 2011, 04:20 PM
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
Tags
Chart
Asked by
jay
Top achievements
Rank 1
Answers by
jay
Top achievements
Rank 1
Giuseppe
Telerik team
Gary
Top achievements
Rank 1
Share this question
or