ComponentOne Chart3D : Tips and Tricks

In this post we are going to provide some useful tips for ComponentOne Chart3D for WPF which are not available out of box.

Tip#1 : Export to PDF

Here the objective is to export the C1Chart3D image to PDF. As such there is no direct way or inbuilt feature provided within the convert the control but we can certainly do this by using our very own C1PdfDocument class. We will create a WriteableBitmap of the ChartImage and will draw the same on an instance of the C1PdfDocument class using its DrawImage method and will save the pdf image in MemoryStream. C1Chart3D_Print

private void Pdf_Click(object sender, RoutedEventArgs e)  
    // use size of visible chart  
    var sz = new Size(chart.ActualWidth, chart.ActualHeight);  

    using (var file = File.Open("chart.jpeg", FileMode.Create))  
        chart.SaveImage(file, ImageFormat.Jpeg);  

    C1PdfDocument doc = new C1PdfDocument();  
    doc.Compression = CompressionLevel.BestCompression;  

    BitmapSource img = ((BitmapSource)GetThumbnail());  
    WriteableBitmap wb = new WriteableBitmap(img);  
    doc.DrawImage(wb, new Rect(new Point(),doc.PageSize), ContentAlignment.TopCenter, Stretch.Uniform);  


    SaveFileDialog sfd = new SaveFileDialog()  
        DefaultExt = "pdf",  
        Filter = "Pdf files (*.pdf)|*.pdf",  

    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)  
        using (var stream = sfd.OpenFile())  

private ImageSource GetThumbnail()  
    byte[] buffer = File.ReadAllBytes("chart.jpeg");  
    MemoryStream memoryStream = new MemoryStream(buffer);  

    BitmapImage bitmap = new BitmapImage();  
    bitmap.StreamSource = memoryStream;  

    return bitmap;  


Tip#2 : Printing C1Chart3D

Printing a C1Chart3D is as easy as printing any Visual object. The code explains itself how one can do it :

private void Prn_Click(object sender, RoutedEventArgs e)  
    var dlg = new System.Windows.Controls.PrintDialog();  
    if (dlg.ShowDialog().Value)  
        dlg.PrintVisual(chart, "ComponentOne Chart3D for WPF");  


Tip#3 : Changing the Color Palette

Often the users wish to change the colors of the Zones being formed in the C1Chart3D, that is, from the default Red to Blue transition. One can certainly modify the ColorPalette by accessing the 'ColorPalette' property of the chart object and adding the desired colors to it :

private void ColorPalette_Click(object sender, RoutedEventArgs e)  
    IList list = new List();  
    //Add the colors as per your requirement  
    chart.ColorPalette = list;  

Let us know in case you have more suggestions or feature requests for the control :) Download Sample CS Download Sample VB


GrapeCity Developer Tools
comments powered by Disqus