Exemplo n.º 1
0
        private void ChartTags()
        {
            System.Windows.Controls.DataVisualization.ResourceDictionaryCollection pieSeriesPalette = new System.Windows.Controls.DataVisualization.ResourceDictionaryCollection();
            Tags = new Dictionary <string, int>();

            foreach (Tag t in Data.Tags)
            {
                Tags.Add(t.Oznaka, 0);
                Brush currentBrush = new BrushConverter().ConvertFromString(t.Boja) as SolidColorBrush;

                ResourceDictionary pieDataPointStyles = new ResourceDictionary();
                Style stylePie = new Style(typeof(PieDataPoint));
                stylePie.Setters.Add(new Setter(PieDataPoint.BackgroundProperty, currentBrush));
                pieDataPointStyles.Add("DataPointStyle", stylePie);
                pieSeriesPalette.Add(pieDataPointStyles);
            }
            dvcTag.Palette = pieSeriesPalette;

            foreach (Event e in Data.Events)
            {
                foreach (Tag t in e.Tags)
                {
                    if (Tags.ContainsKey(t.Oznaka))
                    {
                        Tags[t.Oznaka]++;
                    }
                }
            }
        }
        public static void SetPieChart(Chart chart, List <string> colorShades, List <KeyValuePair <string, int> > data)
        {
            System.Windows.Controls.DataVisualization.ResourceDictionaryCollection pieSeriesPalette = new System.Windows.Controls.DataVisualization.ResourceDictionaryCollection();
            System.Windows.ResourceDictionary pieDataPointStyles = new ResourceDictionary();
            Style stylePie = new Style(typeof(PieDataPoint));

            for (int i = 0; i < colorShades.Count; i++)
            {
                Color color = (Color)ColorConverter.ConvertFromString(colorShades[i]);

                Brush currentBrush = new SolidColorBrush(color);
                stylePie.Setters.Add(new Setter(PieDataPoint.BackgroundProperty, currentBrush));
                pieDataPointStyles.Add("DataPointStyle" + i, stylePie);
                pieSeriesPalette.Add(pieDataPointStyles);
            }

            chart.DataContext = data;

            //chart.Palette = pieSeriesPalette;
            chart.Palette = MakePalette(colorShades);
        }