private void SaveChart(object sender, RoutedEventArgs e)
        {
            SciChartSurface surface     = null;
            string          defaultName = "";

            switch (ReportsTabControl.SelectedIndex)
            {
            case 1:
                surface     = entriesAll;
                defaultName = String.Format("All Entries {0:MM-dd-yyyy}", DateTime.Now);
                break;

            case 2:
                surface     = entriesByDayChart;
                defaultName = String.Format("Entries by Day {0:MM-dd-yyyy}", DateTime.Now);
                break;

            case 3:
                surface     = entriesByWeekChart;
                defaultName = String.Format("Entries by Week {0:MM-dd-yyyy}", DateTime.Now);
                break;

            case 4:
                surface     = entriesByMonthChart;
                defaultName = String.Format("Entries by Month {0:MM-dd-yyyy}", DateTime.Now);
                break;

            case 5:
                surface     = entryDistributionChart;
                defaultName = String.Format("Entries Distribution {0:MM-dd-yyyy}", DateTime.Now);
                break;
            }

            if (surface == null)
            {
                return;
            }

            var saveFileDialog = new SaveFileDialog
            {
                Filter           = "Png|*.png|Jpeg|*.jpeg|Bmp|*.bmp",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                FileName         = defaultName
            };

            if (saveFileDialog.ShowDialog() == true)
            {
                var exportType = (ExportType)saveFileDialog.FilterIndex - 1;

                // Saving chart to file with specified file format
                try
                {
                    surface.ExportToFile(saveFileDialog.FileName, exportType);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error saving chart image: " + ex.Message);
                }
            }
        }
Esempio n. 2
0
 public void TakeScreenShot(SciChartSurface sciChartSurface)
 {
     var dialog = new Microsoft.Win32.SaveFileDialog { Filter = "Image File (*.png)|*.png" };
     if (dialog.ShowDialog() != true) return;
     sciChartSurface.ExportToFile(dialog.FileName, ExportType.Png);
     MessageBox.Show("Screenshot saved successfully", GlobalData.MESSAGEBOXTITLE, MessageBoxButton.OK, MessageBoxImage.Information);
 }