How to draw a graph from a file?

Dec 26, 2013 at 8:44 AM
C#
using System;
using System.IO;
using System.Windows;
using System.Globalization;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;

namespace New_plotter
{

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }

        CultureInfo culture = CultureInfo.InvariantCulture;
        private string[] values;
        private ObservableDataSource<Point> source = null;
        public int flag_m = 0;

        private void Simulation()
        {
            using (FileStream fs = new FileStream("VVV.txt", FileMode.Open, FileAccess.Read))
            {
                using (StreamReader r = new StreamReader(fs))
                {
                    double x = 0;
                    double y1 = 0;
                    string line = r.ReadLine();
                    while (!r.EndOfStream)
                    {
                        line = r.ReadLine();
                        values = line.Split(',');
                        x = Double.Parse(values[0], culture);
                        y1 = Double.Parse(values[flag_m], culture);
                        Point p1 = new Point(x, y1);
                        source.AppendAsync(Dispatcher, p1);
                    }

                }

            }

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            flag_m = 1;
            source = new ObservableDataSource<Point>();
            plotter.AddLineGraph(source, 2, "LINE");
            Simulation();

        }

    }
}
Xaml
<Window x:Class="New_plotter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d3="clr-namespace:Microsoft.Research.DynamicDataDisplay;assembly=DynamicDataDisplay"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <d3:ChartPlotter x:Name="plotter" >
      
        </d3:ChartPlotter>
        <Button Content="Button" HorizontalAlignment="Left" Margin="53,36,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
    
    </Grid>
</Window>
Can I do otherwise?