public StackedPie()
        {
            InitializeComponent();

              // load data from resource
              var data = new CSVData();
              using (Stream stream = Assembly.GetExecutingAssembly().
              GetManifestResourceStream("ChartSamples.Resources.browsers.csv"))
              {
            data.Read(stream, false, false);
              }

              int len = data.Length;
              var vdata = new VersionInfo[len];

              for (int i = 0; i < len; i++)
              {
            vdata[i] = new VersionInfo()
            {
              Name = data[i, 0],
              Version = data[i, 1],
              Value = double.Parse(data[i, 2], CultureInfo.InvariantCulture)
            };
              }

              chart.BeginUpdate();
              chart.Data.ItemsSource = vdata;
              chart.Data.ItemNameBinding = new Binding("Name");

              chart.Aggregate = Aggregate.Sum;

              // first series - total by browser
              var ds1 = new DataSeries()
              {
            ValueBinding = new Binding("Value"),
            PointLabelTemplate = (DataTemplate)Resources["lbl"],
              };
              ds1.PlotElementLoaded += (PlotElementLoaded);
              chart.Data.Children.Add(ds1);

              // second series - browser versions
              var ds2 = new DataSeries()
              {
            ItemsSource = vdata, // own data source(no aggregates)
            ValueBinding = new Binding("Value"),
            PointLabelTemplate = (DataTemplate)Resources["lbl1"],
              };
              ds2.PlotElementLoaded += (PlotElementLoaded);
              chart.Data.Children.Add(ds2);

              // chart type and direction
              chart.ChartType = ChartType.PieStacked;
              PieOptions.SetDirection(chart, SweepDirection.Counterclockwise);

              chart.EndUpdate();
        }
        public MultipleAxes()
        {
            InitializeComponent();

            // read data
            CSVData data = new CSVData();

            using (Stream stream = Assembly.GetExecutingAssembly().
                                   GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
            {
                data.Read(stream, true, true);
            }

            int len = data.Length;

            WeatherData[] wdata = new WeatherData[len];

            double min = double.MaxValue;
            double max = double.MinValue;

            // fill the array
            for (int i = 0; i < len; i++)
            {
                wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
                                           double.Parse(data[i, "Max TemperatureF"]),
                                           double.Parse(data[i, "Mean TemperatureF"]),
                                           double.Parse(data[i, "Min TemperatureF"]));

                min = Math.Min(min, wdata[i].TMin);
                max = Math.Max(max, wdata[i].TMax);
            }

            if (len > 0)
            {
                chart.BeginUpdate();
                chart.Data.Children.Clear();
                chart.Data.ItemsSource = wdata;

                Style ss = (Style)Resources["sstyle"];

                // create data series
                XYDataSeries ds = new XYDataSeries(); ds.Label = "Minimum";
                ds.ValueBinding  = new Binding("TMin");
                ds.XValueBinding = new Binding("DateTime");
                ds.SymbolStyle   = ss;
                chart.Data.Children.Add(ds);

                ds = new XYDataSeries(); ds.Label = "Maximum";
                ds.ValueBinding  = new Binding("TMax");
                ds.XValueBinding = new Binding("DateTime");
                ds.SymbolStyle   = ss;
                chart.Data.Children.Add(ds);

                //ds = new XYDataSeries(); ds.Label = "Average";
                //ds.ValueBinding = new Binding("TAvg");
                //ds.XValueBinding = new Binding("DateTime");
                //ds.SymbolStyle = ss;
                //chart.Data.Children.Add(ds);

                chart.View.AxisX.Min = wdata[0].DateTime.ToOADate();
                chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate();

                chart.View.AxisY.Min = min;
                chart.View.AxisY.Max = max;

                chart.EndUpdate();
            }

            WaitAndDisableAnimation();
        }
        // ** ctor
        public ZoomChartControl()
        {
            InitializeComponent();

              Loaded += new RoutedEventHandler(ZoomChart_Loaded);

              // read data
              CSVData data = new CSVData();
              using (Stream stream = Assembly.GetExecutingAssembly().
              GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
              {
            data.Read(stream, true, false);
              }

              int len = data.Length;
              WeatherData[] wdata = new WeatherData[len];

              double min = double.MaxValue;
              double max = double.MinValue;

              // fill array
              for (int i = 0; i < len; i++)
              {
            wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
            double.Parse(data[i, "Max TemperatureF"]),
            double.Parse(data[i, "Mean TemperatureF"]),
            double.Parse(data[i, "Min TemperatureF"]));

            min = Math.Min(min, wdata[i].TMin);
            max = Math.Max(max, wdata[i].TMax);
              }

              _min = wdata[0].DateTime.ToOADate();
              _max = wdata[len - 1].DateTime.ToOADate();

              if (len > 0)
              {
            chart.BeginUpdate();
            CreateDataSeries(chart, wdata);

            chart.ChartType = ChartType.Line;
            chart.View.AxisX.AnnoFormat = "MMM";
            chart.View.AxisX.MinorTickHeight = 0;
            chart.View.AxisX.Min = _min;
            chart.View.AxisX.Max = _max;

            chart.EndUpdate();

            chartZoom.BeginUpdate();
            CreateDataSeries(chartZoom, wdata);
            chartZoom.ChartType = ChartType.Line;
            chartZoom.View.AxisX.AnnoFormat = "dd-MMM";
            chartZoom.View.AxisX.Max = _min + 0.25 * (_max - _min);
            chartZoom.View.AxisX.MinorTickHeight = 0;
            chartZoom.EndUpdate();
              }
        }
        private void SetTemperatureChart()
        {
            // read data
            CSVData data = new CSVData();
            using (Stream stream = Assembly.GetExecutingAssembly().
                GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
            {
                data.Read(stream, true, true);
            }

            int len = data.Length;
            WeatherData[] wdata = new WeatherData[len];

            double min = double.MaxValue;
            double max = double.MinValue;

            // fill the array
            for (int i = 0; i < len; i++)
            {
                wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
                      double.Parse(data[i, "Max TemperatureF"]),
                      double.Parse(data[i, "Mean TemperatureF"]),
                      double.Parse(data[i, "Min TemperatureF"]));

                min = Math.Min(min, wdata[i].TMin);
                max = Math.Max(max, wdata[i].TMax);
            }

            if (len > 0)
            {
                chart.BeginUpdate();
                chart.Data.Children.Clear();
                chart.Data.ItemsSource = wdata;

                // create data series
                HighLowSeries ds = new HighLowSeries();
                ds.ChartType = ChartType.Gantt;
                ds.Label = "Temp";
                ds.LowValueBinding = new Binding("TMin");
                ds.XValueBinding = new Binding("DateTime");
                ds.HighValueBinding = new Binding("TMax");
                ds.Style = this.Resources["highlowseries"] as Style;

                chart.Data.Children.Add(ds);

                XYDataSeries ds2 = new XYDataSeries();
                ds2.ChartType = ChartType.Line;
                ds2.Label = "Average";
                ds2.ValueBinding = new Binding("TAvg");
                ds2.XValueBinding = new Binding("DateTime");
                chart.Data.Children.Add(ds2);

                // set axis min and max
                chart.View.AxisX.Min = wdata[0].DateTime.Subtract(new TimeSpan(1, 0, 0, 0)).ToOADate();
                chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate();

                chart.View.AxisY.Min = min;
                chart.View.AxisY.Max = max;

                // style chart
                chart.View.AxisX.IsTime = true;
                chart.View.AxisY.MajorTickThickness = 0;
                chart.View.AxisY.MinorTickThickness = 0;
                chart.View.AxisY.AxisLine = new Line() { StrokeThickness = 0 };
                chart.View.AxisX.Scale = 0.4;
                chart.View.AxisX.ScrollBar = new AxisScrollBar();
                chart.View.AxisX.MajorGridStrokeThickness = 0;
                chart.View.AxisX.MinorGridStrokeThickness = 0;
                chart.View.AxisX.MajorTickThickness = 0;
                chart.View.AxisX.MinorTickThickness = 0;
                chart.View.AxisX.AxisLine = new Line() { StrokeThickness = 0 };
                chart.View.AxisY.Title = new TextBlock() { Text = "Temperature", HorizontalAlignment = System.Windows.HorizontalAlignment.Center };

                chart.EndUpdate();
            }
        }
        void chart_Loaded(object sender, RoutedEventArgs e)
        {
            // read data from resource
              CSVData data = new CSVData();

              using (Stream stream = Assembly.GetExecutingAssembly().
            GetManifestResourceStream("ChartSamples.Resources.weather.csv"))
              {
            data.Read(stream, true, false);
              }

              int len = data.Length;
              DateTime[] dts = new DateTime[len];
              double[] t = new double[len];
              Brush red = new SolidColorBrush(Colors.Red);
              Brush blue = new SolidColorBrush(Colors.Blue);

              DateTime day = new DateTime(), dtmin = new DateTime(), dtmax = new DateTime();
              double tmax = double.MinValue, tmin = double.MaxValue;

              // collection for min/max values axis source
              List<KeyValuePair<object, double>> kvals = new List<KeyValuePair<object, double>>();

              // fill up the time and temperature arrays
              // and calculate daily min/max
              for (int i = 0; i < len; i++)
              {
            dts[i] = DateTime.Parse(data[i, "date"] + " " + data[i, "time"],CultureInfo.InvariantCulture);
            t[i] = double.Parse(data[i, "T"],CultureInfo.InvariantCulture);

            if (i == 0)
            {
              day = dts[i].Date; dtmax = dtmin = dts[i]; tmax = tmin = t[i];
            }

            if (dts[i].Date == day)
            {
              if (t[i] > tmax)
              {
            tmax = t[i];
            dtmax = dts[i];
              }
              if (t[i] < tmin)
              {
            tmin = t[i];
            dtmin = dts[i];
              }
            }
            else
            {
              kvals.Add(new KeyValuePair<object, double>(
              new TextBlock() { Text = "low", Foreground = blue }, dtmin.ToOADate()));
              kvals.Add(new KeyValuePair<object, double>(
              new TextBlock() { Text = "high", Foreground = red }, dtmax.ToOADate()));
              day = dts[i].Date; dtmax = dtmin = dts[i]; tmax = tmin = t[i];
            }
              }

              chart.BeginUpdate();

              // create data series
              XYDataSeries ds = new XYDataSeries()
              {
            XValuesSource = dts,
            ValuesSource = t,
            ConnectionStrokeThickness = 2,
            //        ConnectionStroke = new SolidColorBrush(Colors.Green)
              };
              chart.Data.Children.Add(ds);
              chart.ChartType = ChartType.Line;

              double xsc = 0.05;

              // main x-axis for time
              Axis axx = chart.View.AxisX;
              axx.Min = dts[0].ToOADate();
              axx.Max = dts[len - 1].ToOADate();
              axx.Value = 0;
              axx.Scale = xsc;
              axx.IsTime = true;
              axx.MajorUnit = 0.25;
              axx.AnnoFormat = "HH";
              axx.MajorGridStroke = null;
              axx.AnnoTemplate = new TextBlock() { FontSize = 8, Foreground=Foreground};
              axx.Foreground = Foreground;
              axx.ScrollBar = new AxisScrollBar();

              // auxiliary x-axis for dates
              Axis ax = new Axis()
              {
            AxisType = AxisType.X,
            AnnoFormat = "d MMM",
            AnnoPosition = AnnoPosition.Near,
            IsDependent = true,
            MajorUnit = 1,
            IsTime = true,
            MajorGridStroke = Foreground,
            MajorGridStrokeThickness = 1.5
              };
              chart.View.Axes.Add(ax);

              // create auxiliary x-axis for daily min/max
              ax = new Axis()
              {
            AxisType = AxisType.X,
            Position = AxisPosition.Far,
            IsDependent = true,
            //AnnoAngle = -90,
            ItemsSource = kvals,
            MajorGridStroke = new SolidColorBrush(Colors.LightGray),
            MajorGridStrokeThickness = 1,
            MajorGridStrokeDashes = new DoubleCollection() { 1, 2 },
              };
              chart.View.Axes.Add(ax);

              chart.EndUpdate();

              chart.Loaded -= new RoutedEventHandler(chart_Loaded);
        }
        void chart_Loaded(object sender, RoutedEventArgs e)
        {
            // read data from resource
            CSVData data = new CSVData();

            using (Stream stream = Assembly.GetExecutingAssembly().
                                   GetManifestResourceStream("ChartSamples.Resources.weather.csv"))
            {
                data.Read(stream, true, false);
            }

            int len = data.Length;

            DateTime[] dts  = new DateTime[len];
            double[]   t    = new double[len];
            Brush      red  = new SolidColorBrush(Colors.Red);
            Brush      blue = new SolidColorBrush(Colors.Blue);

            DateTime day = new DateTime(), dtmin = new DateTime(), dtmax = new DateTime();
            double   tmax = double.MinValue, tmin = double.MaxValue;

            // collection for min/max values axis source
            List <KeyValuePair <object, double> > kvals = new List <KeyValuePair <object, double> >();

            // fill up the time and temperature arrays
            // and calculate daily min/max
            for (int i = 0; i < len; i++)
            {
                dts[i] = DateTime.Parse(data[i, "date"] + " " + data[i, "time"], CultureInfo.InvariantCulture);
                t[i]   = double.Parse(data[i, "T"], CultureInfo.InvariantCulture);

                if (i == 0)
                {
                    day = dts[i].Date; dtmax = dtmin = dts[i]; tmax = tmin = t[i];
                }

                if (dts[i].Date == day)
                {
                    if (t[i] > tmax)
                    {
                        tmax  = t[i];
                        dtmax = dts[i];
                    }
                    if (t[i] < tmin)
                    {
                        tmin  = t[i];
                        dtmin = dts[i];
                    }
                }
                else
                {
                    kvals.Add(new KeyValuePair <object, double>(
                                  new TextBlock()
                    {
                        Text = "low", Foreground = blue
                    }, dtmin.ToOADate()));
                    kvals.Add(new KeyValuePair <object, double>(
                                  new TextBlock()
                    {
                        Text = "high", Foreground = red
                    }, dtmax.ToOADate()));
                    day = dts[i].Date; dtmax = dtmin = dts[i]; tmax = tmin = t[i];
                }
            }

            chart.BeginUpdate();

            // create data series
            XYDataSeries ds = new XYDataSeries()
            {
                XValuesSource             = dts,
                ValuesSource              = t,
                ConnectionStrokeThickness = 2,
//        ConnectionStroke = new SolidColorBrush(Colors.Green)
            };

            chart.Data.Children.Add(ds);
            chart.ChartType = ChartType.Line;

            double xsc = 0.05;

            // main x-axis for time
            Axis axx = chart.View.AxisX;

            axx.Min             = dts[0].ToOADate();
            axx.Max             = dts[len - 1].ToOADate();
            axx.Value           = 0;
            axx.Scale           = xsc;
            axx.IsTime          = true;
            axx.MajorUnit       = 0.25;
            axx.AnnoFormat      = "HH";
            axx.MajorGridStroke = null;
            axx.AnnoTemplate    = new TextBlock()
            {
                FontSize = 8, Foreground = Foreground
            };
            axx.Foreground = Foreground;
            axx.ScrollBar  = new AxisScrollBar();

            // auxiliary x-axis for dates
            Axis ax = new Axis()
            {
                AxisType                 = AxisType.X,
                AnnoFormat               = "d MMM",
                AnnoPosition             = AnnoPosition.Near,
                IsDependent              = true,
                MajorUnit                = 1,
                IsTime                   = true,
                MajorGridStroke          = Foreground,
                MajorGridStrokeThickness = 1.5
            };

            chart.View.Axes.Add(ax);

            // create auxiliary x-axis for daily min/max
            ax = new Axis()
            {
                AxisType    = AxisType.X,
                Position    = AxisPosition.Far,
                IsDependent = true,
                //AnnoAngle = -90,
                ItemsSource              = kvals,
                MajorGridStroke          = new SolidColorBrush(Colors.LightGray),
                MajorGridStrokeThickness = 1,
                MajorGridStrokeDashes    = new DoubleCollection()
                {
                    1, 2
                },
            };
            chart.View.Axes.Add(ax);

            chart.EndUpdate();

            chart.Loaded -= new RoutedEventHandler(chart_Loaded);
        }
        private void SetTemperatureChart()
        {
            // read data
            CSVData data = new CSVData();

            using (Stream stream = Assembly.GetExecutingAssembly().
                                   GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
            {
                data.Read(stream, true, true);
            }

            int len = data.Length;

            WeatherData[] wdata = new WeatherData[len];

            double min = double.MaxValue;
            double max = double.MinValue;

            // fill the array
            for (int i = 0; i < len; i++)
            {
                wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
                                           double.Parse(data[i, "Max TemperatureF"]),
                                           double.Parse(data[i, "Mean TemperatureF"]),
                                           double.Parse(data[i, "Min TemperatureF"]));

                min = Math.Min(min, wdata[i].TMin);
                max = Math.Max(max, wdata[i].TMax);
            }

            if (len > 0)
            {
                chart.BeginUpdate();
                chart.Data.Children.Clear();
                chart.Data.ItemsSource = wdata;


                // create data series
                HighLowSeries ds = new HighLowSeries();
                ds.ChartType        = ChartType.Gantt;
                ds.Label            = "Temp";
                ds.LowValueBinding  = new Binding("TMin");
                ds.XValueBinding    = new Binding("DateTime");
                ds.HighValueBinding = new Binding("TMax");
                ds.Style            = this.Resources["highlowseries"] as Style;

                chart.Data.Children.Add(ds);

                XYDataSeries ds2 = new XYDataSeries();
                ds2.ChartType     = ChartType.Line;
                ds2.Label         = "Average";
                ds2.ValueBinding  = new Binding("TAvg");
                ds2.XValueBinding = new Binding("DateTime");
                chart.Data.Children.Add(ds2);

                // set axis min and max
                chart.View.AxisX.Min = wdata[0].DateTime.Subtract(new TimeSpan(1, 0, 0, 0)).ToOADate();
                chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate();

                chart.View.AxisY.Min = min;
                chart.View.AxisY.Max = max;

                // style chart
                chart.View.AxisX.IsTime             = true;
                chart.View.AxisY.MajorTickThickness = 0;
                chart.View.AxisY.MinorTickThickness = 0;
                chart.View.AxisY.AxisLine           = new Line()
                {
                    StrokeThickness = 0
                };
                chart.View.AxisX.Scale     = 0.4;
                chart.View.AxisX.ScrollBar = new AxisScrollBar();
                chart.View.AxisX.MajorGridStrokeThickness = 0;
                chart.View.AxisX.MinorGridStrokeThickness = 0;
                chart.View.AxisX.MajorTickThickness       = 0;
                chart.View.AxisX.MinorTickThickness       = 0;
                chart.View.AxisX.AxisLine = new Line()
                {
                    StrokeThickness = 0
                };
                chart.View.AxisY.Title = new TextBlock()
                {
                    Text = "Temperature", HorizontalAlignment = System.Windows.HorizontalAlignment.Center
                };

                chart.EndUpdate();
            }
        }
        public MultipleAxes()
        {
            InitializeComponent();

              // read data
              CSVData data = new CSVData();
              using (Stream stream = Assembly.GetExecutingAssembly().
              GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
              {
              data.Read(stream, true, true);
              }

              int len = data.Length;
              WeatherData[] wdata = new WeatherData[len];

              double min = double.MaxValue;
              double max = double.MinValue;

              // fill the array
              for (int i = 0; i < len; i++)
              {
            wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
              double.Parse(data[i, "Max TemperatureF"]),
              double.Parse(data[i, "Mean TemperatureF"]),
              double.Parse(data[i, "Min TemperatureF"]));

              min = Math.Min(min, wdata[i].TMin);
              max = Math.Max(max, wdata[i].TMax);
              }

              if (len > 0)
              {
              chart.BeginUpdate();
              chart.Data.Children.Clear();
              chart.Data.ItemsSource = wdata;

              Style ss = (Style)Resources["sstyle"];

            // create data series
              XYDataSeries ds = new XYDataSeries(); ds.Label = "Minimum";
              ds.ValueBinding = new Binding("TMin");
              ds.XValueBinding = new Binding("DateTime");
              ds.SymbolStyle = ss;
              chart.Data.Children.Add(ds);

              ds = new XYDataSeries(); ds.Label = "Maximum";
              ds.ValueBinding = new Binding("TMax");
              ds.XValueBinding = new Binding("DateTime");
              ds.SymbolStyle = ss;
              chart.Data.Children.Add(ds);

            //ds = new XYDataSeries(); ds.Label = "Average";
            //ds.ValueBinding = new Binding("TAvg");
            //ds.XValueBinding = new Binding("DateTime");
            //ds.SymbolStyle = ss;
              //chart.Data.Children.Add(ds);

              chart.View.AxisX.Min = wdata[0].DateTime.ToOADate();
            chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate();

              chart.View.AxisY.Min = min;
              chart.View.AxisY.Max = max;

              chart.EndUpdate();
              }

              WaitAndDisableAnimation();
        }