Click here to Skip to main content
12,451,425 members (49,831 online)
Click here to Skip to main content

Stats

271.6K views
4.3K downloads
65 bookmarked
Posted

WPF Charting using MVVM Pattern

, 19 Oct 2010 CPOL
Shows how to implement a WPF Chart in .NET 4.0 using MVVM Pattern
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows;
using System.Windows.Controls;

namespace WPFCharting.Commands
{
    class ShowSeries : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }
        public void Execute(object parameter)
        {
            string SelectedSeriesName = parameter as string;
            if (SelectedSeriesName == null) return;
            ContentControl TemporaryContentControl = null;
            switch (SelectedSeriesName)
            {
                case "AreaSeries":
                    TemporaryContentControl = ucAreaSeries.getInstance();
                    break;
                case "BarSeries" :
                    TemporaryContentControl = ucBarSeries.getInstance();
                    break;
                case "BubbleSeries" :
                    TemporaryContentControl= ucBubbleSeries.getInstance();
                    break;
                case "ColumnSeries":
                    TemporaryContentControl = ucColumnSeriesChart.getInstance();
                    break;
                case "LineSeries":
                    TemporaryContentControl = ucLineSeries.getInstance();
                    break;
                case "PieSeries":
                    TemporaryContentControl = ucPieSeriesChart.getInstance();
                    break;
                case "ScatterSeries":
                    TemporaryContentControl = ucScatterSeries.getInstance();
                    break;
                default:
                    break;
            }
            (MainWindowVM.getInstance()).MainChart = TemporaryContentControl;
        }

        public event EventHandler CanExecuteChanged;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mr. Javaman
Software Developer (Senior)
United States United States
Mr Javaman

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 19 Oct 2010
Article Copyright 2010 by Mr. Javaman
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid