.Save() does not export correctly

4 posts, 1 answers
  1. chris
    chris avatar
    32 posts
    Member since:
    Jul 2011

    Posted 22 Aug 2011 Link to this post

    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?
  2. chris
    chris avatar
    32 posts
    Member since:
    Jul 2011

    Posted 23 Aug 2011 Link to this post

    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?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Missing user
    Missing user avatar

    Posted 25 Aug 2011 Link to this post

    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 >>

  5. chris
    chris avatar
    32 posts
    Member since:
    Jul 2011

    Posted 25 Aug 2011 Link to this post

    Thank you very much, this fixed my problem
Back to Top