Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public StackedPie()
        {
            InitializeComponent();

            var data = new CSVData();

            data.Read(ResKit.GetResource("browsers.csv"), 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])
                };
            }

            _chart.BeginUpdate();
            _chart.Data.ItemsSource = vdata;
            Binding bindingName = new Binding();

            bindingName.Path            = new PropertyPath("Name");
            _chart.Data.ItemNameBinding = bindingName;

            _chart.Aggregate = Aggregate.Sum;

            // first series - total by browser
            Binding valueBinding = new Binding();

            valueBinding.Path = new PropertyPath("Value");
            var ds1 = new DataSeries()
            {
                ValueBinding       = valueBinding,
                PointLabelTemplate = (DataTemplate)Resources["lbl"],
            };

            ds1.PlotElementLoaded += (PlotElementLoaded);
            Canvas.SetZIndex(ds1, 1);
            _chart.Data.Children.Add(ds1);

            // second series - browser versions
            Binding valueBinding2 = new Binding();

            valueBinding2.Path = new PropertyPath("Value");
            var ds2 = new DataSeries()
            {
                ItemsSource        = vdata, // own data source(no aggregates)
                ValueBinding       = valueBinding2,
                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);

            // set palette
            _palette.Add("Internet Explorer", Color.FromArgb(255, 214, 239, 255));
            _palette.Add("Firefox", Color.FromArgb(255, 123, 211, 56));
            _palette.Add("Chrome", Color.FromArgb(255, 239, 21, 123));
            _palette.Add("Safari", Color.FromArgb(255, 255, 186, 0));
            _palette.Add("Opera", Color.FromArgb(255, 0, 174, 222));

            // find max version usage by browser
            foreach (var key in _palette.Keys)
            {
                _maxs[key] = (from item in vdata where item.Name == key select item.Value).Max();
            }

            _chart.EndUpdate();
        }