﻿<Window x:Class="Chart_Columns5.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tk="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
        Title="Two Columns" Height="350" Width="525" Loaded="Window_Loaded">
    <DockPanel LastChildFill="True">
        <Button DockPanel.Dock="Top" Content="Klick mich in die Zwischenablage" Name="bnChart2Clipboard" Click="bnChart2Clipboard_Click" />
        <tk:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart"  Background="LightSteelBlue">
            <tk:Chart.Series  >
                <tk:ColumnSeries  BorderThickness="1" Title=" Monthly Count1" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}" />
            </tk:Chart.Series>
        </tk:Chart>
    </DockPanel>
</Window>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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, search  DataVisualization
//   System.Windows.Controls.DataVisualization.Toolkit
using System.Windows.Controls.DataVisualization.Charting;

namespace Chart_Columns5 {
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {

        private List<ModelChart> chartListe = null;


        public MainWindow() {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e) {
            mcChart.LegendTitle = "Legende";

            // create Data, this should get per Params in the constructor
            chartListe = new List<ModelChart>();
            chartListe.Add( new ModelChart("Januar",1234.5m));
            chartListe.Add( new ModelChart("Februar",434.5m));
            chartListe.Add( new ModelChart("März",334.65m));
            chartListe.Add( new ModelChart("April",865.5m));
            chartListe.Add( new ModelChart("Mai",198.5m));
            chartListe.Add( new ModelChart("Juni",234.5m));


            KeyValuePair<String, decimal>[] valuesXY = new KeyValuePair<String, decimal>[chartListe.Count];
            for (int i = 0; i < chartListe.Count; i++) {
                valuesXY[i] = new KeyValuePair<string, decimal>(chartListe[i].xValue, chartListe[i].yValue);
            }

            ColumnSeries cs1 = ((ColumnSeries)mcChart.Series[0]);
            cs1.ItemsSource = valuesXY;

        }


        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);
        }

    }
}



// ModelChart 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chart_Columns5 {
    public class ModelChart {
        
        public String xValue = "";
        public decimal yValue = 0.0m;

        public ModelChart(String xValue, decimal yValue) {
            this.xValue = xValue;
            this.yValue = yValue;
        }

    }
}
