using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
// Reference Assemblies / Framework
// System.Windows.Controls.DataVisualization.Toolkit
using System.Windows.Controls.DataVisualization.Charting;
namespace Chart_Scatter1 {
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
mcChart.LegendTitle = "Legende";
ScatterSeries st0 = ((ScatterSeries)mcChart.Series[0]);
st0.ItemsSource =
new KeyValuePair[]{
new KeyValuePair(DateTime.Now, 100),
new KeyValuePair(DateTime.Now.AddMonths(1), 130),
new KeyValuePair(DateTime.Now.AddMonths(2), 150),
new KeyValuePair(DateTime.Now.AddMonths(3), 125),
new KeyValuePair(DateTime.Now.AddMonths(4),155) };
st0.Foreground = new SolidColorBrush(Colors.Blue);
st0.Background = new SolidColorBrush(Colors.Blue);
st0.BorderBrush = new SolidColorBrush(Colors.Black);
ScatterSeries st1 = ((ScatterSeries)mcChart.Series[1]);
st1.ItemsSource =
new KeyValuePair[]{
new KeyValuePair(DateTime.Now, 200),
new KeyValuePair(DateTime.Now.AddMonths(3), 230),
new KeyValuePair(DateTime.Now.AddMonths(5), 250),
new KeyValuePair(DateTime.Now.AddMonths(6), 225),
new KeyValuePair(DateTime.Now.AddMonths(7),255) };
//ls2.Foreground = Brushes.Red;
st1.Foreground = new SolidColorBrush(Colors.Red);
st1.Background = new SolidColorBrush(Colors.Red);
st1.BorderBrush = new SolidColorBrush(Colors.Blue);
}
private void bnChart2Clipboard_Click(object sender, RoutedEventArgs e) {
CopyUIElementToClipboard(mcChart);
}
// source: http://elegantcode.com/2010/12/13/wpfcopy-uielement-to-clipboard-as-multiple-formats/
public static void CopyUIElementToClipboard(FrameworkElement element) {
//data object to hold our different formats representing the element
DataObject dataObject = new DataObject();
//lets start with the text representation
//to make is easy we will just assume the object set as the DataContext has the ToString method overrideen and we use that as the text
dataObject.SetData(DataFormats.Bitmap, element, true);
//now lets do the image representation
double width = element.ActualWidth;
double height = element.ActualHeight;
RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96, PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen()) {
VisualBrush vb = new VisualBrush(element);
dc.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
}
bmpCopied.Render(dv);
dataObject.SetData(DataFormats.Bitmap, bmpCopied, true);
//now place our object in the clipboard
Clipboard.SetDataObject(dataObject, true);
}
}
}