Quantcast
Channel: Our ComponentOne » All Posts
Viewing all articles
Browse latest Browse all 14170

Printing C1Chart via Writeablebitmap or is There Another Way?

$
0
0

Hello! I am in need of being able to print several dozen (if not hundreds) of charts into a report. I would need to do this in code, not visible to the user. I have tried the following code, with no luck:

foreach (Curve c in allReferenceCurves)
           {
               …
 
               WriteableBitmap wb_g = new WriteableBitmap(CreateVirtualChart(XValues, YValues, X1Values, Y1Values, allGammas), null);
               doc.DrawString(label, font, Colors.Black, rc);
               doc.DrawImage(wb_g, new Rect(new Point(), doc.PageSize), ContentAlignment.TopLeft, Stretch.None);
 
               doc.NewPage();
 
              …
           }
C1Chart CreateVirtualChart(List<double> xValues, List<double> yValues,
                                  List<double> x1Values, List<double> y1Values, List<double> gamma)
        {
            C1Chart virtualChart = new C1Chart();
            virtualChart.Children.Clear();
            virtualChart.View.Children.Clear();
            virtualChart.Data.Children.Clear();
 
 
            // Create new DataSeries
            XYDataSeries dataSeries3 = new XYDataSeries();
 
            //gammaChart.View.Axes.Add(gammaAxis);
 
            // create and add a new axis to the chart
            // since you will be reloading this over and over, don’t add Axis if it has already been created
            if (chartSet != true)
            {
                Axis ax3 = new Axis();
                ax3.Name = "ax3″;
                ax3.AxisType = AxisType.Y;
                ax3.Position = AxisPosition.Far;
                virtualChart.View.Axes.Add(ax3);
                chartSet = true;
            }
 
            dataSeries3.XValuesSource = xValues;
            dataSeries3.ValuesSource = gamma;
            dataSeries3.AxisY = "ax3″;
 
            virtualChart.Data.Children.Add(dataSeries3);
            virtualChart.Data.Children[0].ChartType = ChartType.Bar;
 
            // Create new DataSeries
            XYDataSeries dataSeries1 = new XYDataSeries();
 
            dataSeries1.XValuesSource = xValues;
            dataSeries1.ValuesSource = yValues;
 
            virtualChart.Data.Children.Add(dataSeries1);
            virtualChart.Data.Children[1].ChartType = ChartType.Line;
 
            // Create new DataSeries
            XYDataSeries dataSeries2 = new XYDataSeries();
 
            dataSeries2.XValuesSource = x1Values;
            dataSeries2.ValuesSource = y1Values;
 
            virtualChart.Data.Children.Add(dataSeries2);
            virtualChart.Data.Children[2].ChartType = ChartType.Line;
 
            virtualChart.UpdateLayout();
 
            return virtualChart;
        }

The basic idea is I have a data source that I want to print multiple charts from, then save the images somehow to PDF. Although, all I get right now is a blank PDF (besides the DrawString() lines). I am wondering if it has something to do with the chart not being displayed?

Any help would be greatly appreciated!

Thanks,
Jon


Viewing all articles
Browse latest Browse all 14170

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>