示例#1
0
 private void drawGraph()
 {
     if (!isCutVersionOfDataTable)
     {
         List <string> studyKeys = pointsDict.Keys.ToList <string>();
         foreach (string studyKey in studyKeys)
         {
             List <string> typeKeys = pointsDict[studyKey].Keys.ToList <string>();
             foreach (string typeKey in typeKeys)
             {
                 LineSeries newChart = new LineSeries();
                 newChart.DependentValuePath   = "Y";
                 newChart.IndependentValuePath = "X";
                 newChart.Title       = studyKey + " | " + typeKey;
                 newChart.ItemsSource = pointsDict[studyKey][typeKey];
                 newChart.Refresh();
                 Charts.Series.Add(newChart);
             }
         }
     }
     else
     {
         List <string> studyKeys = pointsDictForStudy.Keys.ToList <string>();
         foreach (string studyKey in studyKeys)
         {
             LineSeries newChart = new LineSeries();
             newChart.DependentValuePath   = "Y";
             newChart.IndependentValuePath = "X";
             newChart.Title       = studyKey;
             newChart.ItemsSource = pointsDictForStudy[studyKey];
             newChart.Refresh();
             Charts.Series.Add(newChart);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Called when the category setting is toggled. Adds or removes a series from the chart
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CategoryToggle_Toggled(object sender, RoutedEventArgs e)
        {
            // Get the name of the catefory from the toggle switch
            string CategoryName = ((sender as ToggleSwitch).OnContent as string);

            // Check to see if it was toggled on or off
            if ((sender as ToggleSwitch).IsOn)
            {
                List <Expense>       TempItems;
                List <DateValueItem> TempChartData  = new List <DateValueItem>();
                LineSeries           CategorySeries = new LineSeries();
                Binding CategorySeriesIVBinding     = new Binding();
                Binding CategorySeriesDVBinding     = new Binding();
                Style   CategoryYAxisStyle          = new Style(typeof(NumericAxisLabel));
                Style   CategoryXAxisStyle          = new Style(typeof(DateTimeAxisLabel));
                Setter  Hide = new Setter(VisibilityProperty, Visibility.Collapsed);

                // Set the axis stule for the series
                CategoryYAxisStyle.Setters.Add(Hide);
                CategoryXAxisStyle.Setters.Add(Hide);

                // Set the path bindings for the X and Y axis data.
                CategorySeriesIVBinding.Path = new PropertyPath("Date");
                CategorySeriesDVBinding.Path = new PropertyPath("Value");

                // Find all the expenses for the category
                if (CategoryName == "Total Expenses")
                {
                    TempItems = Expenses;
                }
                else
                {
                    TempItems = Expenses.FindAll(a => a.Category == CategoryName);
                }

                // Add all the expenses to a list for displaying
                foreach (Expense i in TempItems)
                {
                    TempChartData.Add(new DateValueItem {
                        Date = (i.Date + i.Time.TimeOfDay), Value = (int)i.Price, Id = i.Id
                    });
                }

                // Setup the series
                CategorySeries.Name                    = CategoryName + "Series";
                CategorySeries.Title                   = CategoryName;
                CategorySeries.ItemsSource             = TempChartData;
                CategorySeries.IndependentValueBinding = CategorySeriesIVBinding;
                CategorySeries.DependentValueBinding   = CategorySeriesDVBinding;
                CategorySeries.IsSelectionEnabled      = true;
                CategorySeries.SelectionChanged       += DataPointTapped;
                CategorySeries.IndependentAxis         = ((ExpenseChart.Series[0] as LineSeries).IndependentAxis as DateTimeAxis);
                CategorySeries.DependentRangeAxis      = ((ExpenseChart.Series[0] as LineSeries).DependentRangeAxis as LinearAxis);
                CategorySeries.DataPointStyle          = StyleService.LargeDataPoint(StyleService.Colours[ExpenseChart.Series.Count]);

                // Get the rectangle for the category to colour to match the series colour
                foreach (StackPanel i in ChartSettings.Items)
                {
                    if ((i.Children[0] as ToggleSwitch) == (sender as ToggleSwitch))
                    {
                        (i.Children[1] as Rectangle).Fill = new SolidColorBrush(StyleService.Colours[ExpenseChart.Series.Count]);
                    }
                }

                // Add the series to the chart
                ExpenseChart.Series.Add(CategorySeries);
                CategorySeries.Refresh();
            }
            // If the switch is turned off, remove the series
            else
            {
                // Find the series for the toggle by category name and remove it
                foreach (LineSeries i in ExpenseChart.Series)
                {
                    if ((string)i.Title == CategoryName)
                    {
                        ExpenseChart.Series.Remove(i);
                        break;
                    }
                }
                //  Find the ractangle for the category and colour it gray
                foreach (StackPanel i in ChartSettings.Items)
                {
                    if ((i.Children[0] as ToggleSwitch) == (sender as ToggleSwitch))
                    {
                        (i.Children[1] as Rectangle).Fill = new SolidColorBrush(Colors.Gray);
                        break;
                    }
                }

                // Recolour all the remaining line series to be the colour for they're position in the series list
                foreach (LineSeries i in ExpenseChart.Series)
                {
                    i.DataPointStyle = StyleService.LargeDataPoint(StyleService.Colours[ExpenseChart.Series.IndexOf(i)]);
                    foreach (StackPanel j in ChartSettings.Items)
                    {
                        if (ChartSettings.Items.IndexOf(j) > 0)
                        {
                            if (((j.Children[0] as ToggleSwitch).OnContent as string) == (i.Title as string))
                            {
                                (j.Children[1] as Rectangle).Fill = new SolidColorBrush(StyleService.Colours[ExpenseChart.Series.IndexOf(i)]);
                            }
                        }
                    }
                }
            }
        }