Example #1
0
        public void PopulateCharts(Dictionary <string, int> listeTest)
        {
            List <Color> ListeCouleurs = new List <Color>();

            ListeCouleurs.Add(Colors.Blue);
            ListeCouleurs.Add(Colors.CadetBlue);
            ListeCouleurs.Add(Colors.Blue);
            ListeCouleurs.Add(Colors.Cyan);
            ListeCouleurs.Add(Colors.Azure);
            ListeCouleurs.Add(Colors.DarkBlue);
            ListeCouleurs.Add(Colors.DarkSlateBlue);

            collection1 = new PieDataCollection <PieSegment>();
            collection1.CollectionName = "Animals";
            int cpt = 0;

            foreach (KeyValuePair <string, int> pair in listeTest)
            {
                if (cpt == 0)
                {
                    graphique.Text = pair.Key + ": " + pair.Value;
                }
                else
                {
                    collection1.Add(new PieSegment {
                        Color = ListeCouleurs[cpt], Value = pair.Value, Name = pair.Key
                    });
                }
                cpt++;
            }

            chart.Data       = collection1;
            chart.PopupBrush = Brushes.LightCoral;
        }
        private void PrepareData()
        {
            Data = new PieDataCollection
            {
                new PieData {Title = string.Empty},
                new PieData {Title = string.Empty}
            };

            var progress = (int)Math.Round(Progress); // lets show only the round off value
            if (Progress > 100)
                progress = 100;
            if (Progress < 0)
                progress = 0;

            Data[0].Value = progress;
            Data[0].Title = ProgressTitle;
            Data[1].Value = 100 - progress;

            ProgressValueTextBlock.Text = progress + " %";
        }
 public PieChart()
 {
     InitializeComponent();
     Data = new PieDataCollection {new PieData(), new PieData()};
     Loaded += PieChart_Loaded;
 }
Example #4
0
 void InitializeChart(string RegLocation)
 {
     collection = new PieDataCollection<PieSegment>();
     //clear values
     ColorCount = ReturnedSeconds = TotalSec = 0;
     try
     {
         //get all value in a key(from reg.)
         foreach (string aplicatie in Registry.CurrentUser.OpenSubKey(RegLocation, true).GetValueNames())
         {
             //get the stored seconds for the source app name
             ReturnedSeconds = Convert.ToInt32(Registry.CurrentUser.OpenSubKey(RegLocation, true).GetValue(aplicatie));
             //add the item to the pie collection
             //set the next found color in the array to the pie chart
             //set the name of the application and the value by seconds
             collection.Add(new PieSegment { Color = _Colors[ColorCount], Value = ReturnedSeconds, Name = aplicatie.ToString() });
             //store all seconds in a int var to calculate the total spended time
             TotalSec += ReturnedSeconds;
             //represent the next color in the array
             ColorCount++;
         }
         //update the UI with the total spended time
         ToatalSpendTimeLbl.Content = "Total spended time in this day: " + TimeSpan.FromSeconds(TotalSec).ToString();
         if (TotalSec == 0) { 
             StatusLbl.Visibility = System.Windows.Visibility.Visible;
             collection.Clear();
         }
         else
         {
             StatusLbl.Visibility = System.Windows.Visibility.Hidden;
         }
     }
     catch (NullReferenceException)
     {//this error appers when no data found in the specified key of the reg. directory
         //Try to create the application registry key
         Registry.CurrentUser.CreateSubKey(RegLocation);
     }
     chart1.Data = collection;
 }