This question is locked. New answers and comments are not allowed.
Hi, I tried to print a radchart as shown in Vladimir Enchev's blog. Unfortunately, it doesn't show dataseries. Any suggestions? Here my code...
public RadChart GetChart() |
{ |
RadChart telerikChart = new RadChart(); |
Grid grid = new Grid(); |
grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(25, GridUnitType.Auto)}); |
grid.RowDefinitions.Add(new RowDefinition()); |
grid.ColumnDefinitions.Add(new ColumnDefinition()); |
grid.ColumnDefinitions.Add(new ColumnDefinition()); |
grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(100, GridUnitType.Auto)}); |
telerikChart.UseDefaultLayout = false; |
telerikChart.Content = grid; |
//Monthly Sales for 2009 |
//Chart Title |
ChartTitle monthlySalesTitle = new ChartTitle(); |
monthlySalesTitle.Content = "Monthly Sales for 2009"; |
monthlySalesTitle.HorizontalAlignment = HorizontalAlignment.Center; |
grid.Children.Add(monthlySalesTitle); |
//Chart Area |
ChartArea monthlySalesChart = new ChartArea(); |
monthlySalesChart.EnableAnimations = false; |
monthlySalesChart.EnableStripLinesAnimation = false; |
Grid.SetRow(monthlySalesChart, 1); |
grid.Children.Add(monthlySalesChart); |
DataSeries monthlySalesDataSeries = new DataSeries(); |
monthlySalesDataSeries.Definition = new BarSeriesDefinition(); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 38, XCategory = "Jan"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 65, XCategory = "Feb"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 30, XCategory = "Mar"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 63, XCategory = "Apr"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 98, XCategory = "May"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 47, XCategory = "Jun"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 91, XCategory = "Jul"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 99, XCategory = "Aug"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 32, XCategory = "Sep"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 77, XCategory = "Oct"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 62, XCategory = "Nov"}); |
monthlySalesDataSeries.Add(new DataPoint {YValue = 38, XCategory = "Dec"}); |
monthlySalesChart.DataSeries.Add(monthlySalesDataSeries); |
//Sales Per Manufacturer |
//Chart Title |
ChartTitle perManufacturerTitle = new ChartTitle(); |
perManufacturerTitle.Content = "Sales per Manufacturer"; |
perManufacturerTitle.HorizontalAlignment = HorizontalAlignment.Center; |
Grid.SetColumn(perManufacturerTitle, 1); |
grid.Children.Add(perManufacturerTitle); |
////Chart Legend |
ChartLegend legend = new ChartLegend(); |
legend.UseAutoGeneratedItems = true; |
legend.Header = string.Empty; |
legend.Name = "ChartLegendManufacturers"; |
Grid.SetColumn(legend, 2); |
Grid.SetRow(legend, 1); |
grid.Children.Add(legend); |
////Chart Area |
ChartArea perManufacturerChart = new ChartArea(); |
perManufacturerChart.LegendName = "ChartLegendManufacturers"; |
Grid.SetRow(perManufacturerChart, 1); |
Grid.SetColumn(perManufacturerChart, 1); |
grid.Children.Add(perManufacturerChart); |
DataSeries perManufacturerDataSeries = new DataSeries(); |
perManufacturerDataSeries.Definition = new DoughnutSeriesDefinition(); |
perManufacturerDataSeries.Definition.ItemLabelFormat = "p"; |
perManufacturerDataSeries.Add(new DataPoint {YValue = 0.215208267, LegendLabel = "Toyota"}); |
perManufacturerDataSeries.Add(new DataPoint {YValue = 0.192960612, LegendLabel = "General Motors"}); |
perManufacturerDataSeries.Add(new DataPoint {YValue = 0.151830229, LegendLabel = "Volkswagen"}); |
perManufacturerDataSeries.Add(new DataPoint {YValue = 0.125964366, LegendLabel = "Ford"}); |
perManufacturerDataSeries.Add(new DataPoint {YValue = 0.091152353, LegendLabel = "Honda"}); |
perManufacturerDataSeries.Add(new DataPoint {YValue = 0.079093251, LegendLabel = "Nissan"}); |
perManufacturerDataSeries.Add(new DataPoint {YValue = 0.079093251, LegendLabel = "PSA"}); |
perManufacturerDataSeries.Add(new DataPoint {YValue = 0.064697675, LegendLabel = "Hyundai"}); |
perManufacturerChart.DataSeries.Add(perManufacturerDataSeries); |
return telerikChart; |
} |
private void ButtonPrint_Click(object sender, RoutedEventArgs e) |
{ |
RadChart chartToPrint = GetChart(); |
Print(chartToPrint, "test"); |
} |
public static void Print(UIElement source, string documentName) |
{ |
var doc = new PrintDocument(); |
var offsetY = 0d; |
var totalHeight = 0d; |
var canvas = new Canvas(); |
canvas.Children.Add(source); |
doc.PrintPage += (s, e) => |
{ |
e.PageVisual = canvas; |
if (totalHeight == 0) |
{ |
totalHeight = source.DesiredSize.Height; |
} |
Canvas.SetTop(source, -offsetY); |
offsetY += e.PrintableArea.Height; |
e.HasMorePages = offsetY <= totalHeight; |
}; |
doc.Print(documentName); |
} |