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

Export chart image to jpeg

2 Answers 142 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Sireesha Janga
Top achievements
Rank 1
Sireesha Janga asked on 14 Jul 2010, 12:03 AM
I am trying to export my WPF chart control to an image but I am getting an exception saying "Object reference not set". I am wondering what I am doing wrong here.
I am trying to export to xps. 
My another requirement is to convert to jpeg.
Can you guys please help me doing this?


SeriesMapping
sm1 = new SeriesMapping();
sm1.SeriesDefinition =
new LineSeriesDefinition();
sm1.LegendLabel =
"Line Series 1";
sm1.CollectionIndex = 0;
ItemMapping im1 = new ItemMapping();
im1.DataPointMember =
DataPointMember.YValue;
sm1.ItemMappings.Add(im1);
SeriesMapping sm2 = new SeriesMapping();
sm2.SeriesDefinition =
new LineSeriesDefinition();
sm2.LegendLabel =
"Line Series 2";
sm2.CollectionIndex = 1;
ItemMapping im2 = new ItemMapping();
im2.DataPointMember =
DataPointMember.YValue;
sm2.ItemMappings.Add(im2);
var itemsSource = new List<double>[] { new List<double> { 9, 2, 3, 4 }, new List<double> { 5, 7, 3, 4 } };
this.RadChart1.SeriesMappings.Add(sm1);
this.RadChart1.SeriesMappings.Add(sm2);
this.RadChart1.ItemsSource = itemsSource;
Microsoft.Win32.
SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.DefaultExt =
".xps";
string fileName = string.Empty; 

if (!((bool)dlg.ShowDialog()))
{
fileName = dlg.FileName;
}
this.RadChart1.ExportToXps(fileName);

2 Answers, 1 is accepted

Sort by
0
Sireesha Janga
Top achievements
Rank 1
answered on 15 Jul 2010, 06:53 PM
Can anybody please help here?
0
Nikolay
Telerik team
answered on 16 Jul 2010, 12:11 PM
Hello Sireesha Janga,

Currently it is not possible to export RadChart straight from code. It is in our plans to introduce this in one of the future versions of the control, but we cannot commit a concrete timeframe for its implementation.

Meanwhile, the easiest work-around would be creating a export button, similarly to the Export example in our demo . Here is a sample demonstrating how to export a .jpeg file:
private void ButtonExportChart_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.DefaultExt = ".jpeg";
            string fileName = string.Empty;
            if ((bool)dlg.ShowDialog())
            {
                fileName = dlg.FileName;
                this.RadChart1.ExportToImage(fileName);
            }
}

Hope this helps.

Sincerely yours,
Nikolay
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
Sireesha Janga
Top achievements
Rank 1
Answers by
Sireesha Janga
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or