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

.Save() does not export correctly

3 Answers 90 Views
Chart
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 22 Aug 2011, 10:57 PM
Hello everyone,

I have a chart named chart1 and I am trying to export the chart as a png file, This is my code:


            var dialog = new SaveFileDialog();
            dialog.DefaultExt = ".png";
            dialog.Filter = string.Format("*.{0} | {1} File", "png", "PNG");

            if (!(bool)dialog.ShowDialog())
                return;

            this.Chart1.Save("Test.png", 96d, 96d, new PngBitmapEncoder());

The dialog box opens correctly and allows me to select a location and a name for the file, but then the file does not save. Any ideas?

3 Answers, 1 is accepted

Sort by
0
chris
Top achievements
Rank 1
answered on 23 Aug 2011, 03:40 PM
I have done more research into this using example I have found on the internet, and they all have dialog.FileName, and FileStream which in my code it says the names cannot be resolved.

private void SaveAsPng()
{
           SaveFileDialog dialog = new SaveFileDialog();
            dialog.DefaultExt = ".png";
            dialog.Filter = string.Format("*.{0} | {1} File", "png", "PNG");
 
            if (!(bool)dialog.ShowDialog())
                return;
            var name = dialog.FileName;
 
            this.Chart1.Save("Test.png", 96d, 96d, new PngBitmapEncoder());
}
 
private void SaveAsXls()
{
 
            fileStream.Open();
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.DefaultExt = "xls";
            dialog.Filter = "*.xls | Excel";
            if (!(bool)dialog.ShowDialog())
                return;
            Chart1.ExportToExcelML(dialog.FileName);
            fileStream.Close();
}


is there some code I am missing to get this working?
0
Accepted
Missing User
answered on 25 Aug 2011, 03:05 PM
Hello Chris,

RadChart control provides built-in export functionality. In order to export the chart to an image you can use RadChart.ExportToImage(...). As parameter you can pass stream or a file name. For example:

exports an image of the chart to stream:
private void ButtonExportChart_Click(object sender, RoutedEventArgs e)
{
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.DefaultExt = "png";
    dialog.Filter = "PNG File (*.png) | *.png";
 
    if (!(bool)dialog.ShowDialog())
        return;
 
    Stream fileStream = dialog.OpenFile();
    radChart.ExportToImage(fileStream, new PngBitmapEncoder());
    fileStream.Close();
}

or exports an image of the chart to file:
private void ButtonExportChart_Click(object sender, RoutedEventArgs e)
{
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.DefaultExt = "png";
    dialog.Filter = "PNG File (*.png) | *.png";
    if (!(bool)dialog.ShowDialog())
        return;
 
    this.radChart.ExportToImage(dialog.FileName, new PngBitmapEncoder());
}

More information about exporting RadChart can be found in this help topic. If the issue persists, please open a support ticket and send us a sample runnable project that demonstrates your implementation. We will investigate it locally and advice you further.

Kind regards,
Polina
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
chris
Top achievements
Rank 1
answered on 25 Aug 2011, 03:08 PM
Thank you very much, this fixed my problem
Tags
Chart
Asked by
chris
Top achievements
Rank 1
Answers by
chris
Top achievements
Rank 1
Missing User
Share this question
or