Esempio n. 1
0
        public void AccidentsComparison(List <Report> reports)
        {
            GenerateChartLabel("Accidents Comparison", new Point(80, 320));

            LiveCharts.WinForms.PieChart pieChart1 = new LiveCharts.WinForms.PieChart();
            pieChart1.InnerRadius    = 20;
            pieChart1.LegendLocation = LegendLocation.Bottom;
            AddChartToForm(pieChart1, new Point(80, 360));

            var tooltip = new DefaultTooltip
            {
                SelectionMode = TooltipSelectionMode.OnlySender
            };
            Func <ChartPoint, string> labelPoint = chartPoint =>
                                                   string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);

            pieChart1.DataTooltip = tooltip;

            pieChart1.Series = new SeriesCollection();
            reports.ForEach(r =>
            {
                pieChart1.Series.Add(new PieSeries
                {
                    Title  = r.Name,
                    Values = new ChartValues <double> {
                        r.Accidents
                    },
                    LabelPoint = labelPoint,
                    DataLabels = true
                });
            });
        }
Esempio n. 2
0
        public AdminGrafico()
        {
            InitializeComponent();

            graficoPastel = new Piechart();
            this.Controls.Add(graficoPastel);
        }
Esempio n. 3
0
        private void frmAdmin_Load(object sender, EventArgs e)
        {
            UpdateTable();
            UpdateCmbBusiness();
            UpdatedgvShowOrders();
            //Gráfico de pastel
            PieChart pieGraphic = new PieChart();

            Controls.Add(pieGraphic);
            pieGraphic.Parent = tabControl1.TabPages[5];
            pieGraphic.Top    = 10;
            pieGraphic.Left   = 10;
            pieGraphic.Width  = pieGraphic.Parent.Width - 20;
            pieGraphic.Height = pieGraphic.Parent.Height - 20;
            pieGraphic.Series = null;
            SeriesCollection collection = new SeriesCollection();
            DataTable        dataTable  = ProductDAO.GetSumByProduct();

            foreach (DataRow row in dataTable.Rows)
            {
                collection.Add(new PieSeries
                {
                    Title = row[0].ToString(), Values = new ChartValues <int> {
                        Convert.ToInt32(row[1].ToString())
                    },
                    DataLabels = true
                });
            }

            pieGraphic.Series         = collection;
            pieGraphic.LegendLocation = LegendLocation.Bottom;
        }
Esempio n. 4
0
        public static void ClearChart(LiveCharts.WinForms.CartesianChart barChart, LiveCharts.WinForms.PieChart pieChart)
        {
            pieChart.Series.Clear();
            pieChart.AxisY.Clear();
            pieChart.AxisX.Clear();
            pieChart.Refresh();

            barChart.Series.Clear();
            barChart.AxisY.Clear();
            barChart.AxisX.Clear();
            barChart.Refresh();
        }
Esempio n. 5
0
 private void setValuePChart(LiveCharts.WinForms.PieChart pChart, PlayerData playerData)
 {
     pChart.Series[0].Values = new ChartValues <double> {
         playerData.NbWin
     };
     pChart.Series[1].Values = new ChartValues <double> {
         playerData.NbEqual
     };
     pChart.Series[2].Values = new ChartValues <double> {
         playerData.NbLose
     };
     pChart.Series[3].Values = new ChartValues <double> {
         playerData.NbInsurance
     };
 }
Esempio n. 6
0
        public void SimulationsPerGrid()
        {
            GenerateChartLabel("Number of Simulations" + "\n" + "Per Grid Size", new Point(80, 10));

            LiveCharts.WinForms.PieChart pieChart1 = new LiveCharts.WinForms.PieChart();
            pieChart1.InnerRadius    = 30;
            pieChart1.LegendLocation = LegendLocation.Right;
            AddChartToForm(pieChart1, new Point(100, 66));

            var tooltip = new DefaultTooltip
            {
                SelectionMode = TooltipSelectionMode.OnlySender
            };

            pieChart1.DataTooltip = tooltip;

            pieChart1.Series = new SeriesCollection
            {
                new PieSeries
                {
                    Title  = "Small",
                    Values = new ChartValues <double> {
                        data.GetSmallGridSimulationsCount()
                    },
                    PushOut    = 5,
                    DataLabels = true
                },
                new PieSeries
                {
                    Title  = "Medium",
                    Values = new ChartValues <double> {
                        data.GetMediumGridSimulationsCount()
                    },
                    DataLabels = true
                },
                new PieSeries
                {
                    Title  = "Large",
                    Values = new ChartValues <double> {
                        data.GetLargeGridSimulationsCount()
                    },
                    DataLabels = true
                },
            };
        }
Esempio n. 7
0
        public LiveCharts.WinForms.PieChart CreatePieChart(List <Summary> mySummary)
        {
            var chart = new LiveCharts.WinForms.PieChart();

            chart.Name = "pieControl";

            Func <ChartPoint, string> labelPoint = chartPoint =>
                                                   string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);

            foreach (Summary s in mySummary)
            {
                var series = new PieSeries
                {
                    Title      = s.MsgText,
                    Values     = new ChartValues <int> {
                    },
                    DataLabels = false,
                    Foreground = foreGround,
                    FontFamily = fontFamily,
                    FontWeight = fontWeight,
                    FontSize   = 11,
                };
                chart.Series.Add(series);
                chart.Series[chart.Series.Count - 1].Values.Add(Convert.ToInt32(s.StopDuration.TotalMinutes));
            }

            chart.LegendLocation           = LegendLocation.Right;
            chart.DefaultLegend.FontFamily = fontFamily;
            chart.DefaultLegend.FontWeight = fontWeight;
            chart.DefaultLegend.Margin     = new System.Windows.Thickness(10, 1, 1, 1);
            chart.DefaultLegend.FontSize   = 15;
            chart.DefaultLegend.Foreground = foreGround;
            System.Drawing.Image img = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\ChartBackground2.png");
            chart.BackgroundImage       = img;
            chart.BackgroundImageLayout = ImageLayout.Stretch;
            chart.Dock            = DockStyle.Fill;
            chart.Text            = "Stop analysis";
            chart.AnimationsSpeed = animationSpeed;

            return(chart);
        }
Esempio n. 8
0
        public static void BindChartData(LiveCharts.WinForms.CartesianChart stringBarChart, LiveCharts.WinForms.PieChart stringPieChart)
        {
            ClearChart(stringBarChart, stringPieChart);

            if (stringListValuePairs.Any())
            {
                Random            randomColorGenerator = new Random();
                ChartValues <int> occurrences          = new ChartValues <int>();
                List <string>     yAxisValues          = new List <string>();
                int i = 0;
                foreach (KeyValuePair <string, int> keyValuePair in stringListValuePairs)
                {
                    if (!string.IsNullOrWhiteSpace(keyValuePair.Key))
                    {
                        occurrences.Add(keyValuePair.Value);
                        yAxisValues.Add(keyValuePair.Key);
                    }
                    i++;
                }
                if (i > 100)
                {
                    MessageBoxProcessor.Show("Bei mehr als 100 Einträgen müssen Sie heranzoomen um die einzelnen Einträge richtig anzuzigen." + Environment.NewLine + "Nutzen Sie hierzu das Scrollrad", "Viele Einträge", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                #region stringBarChart

                var tooltip = new DefaultTooltip
                {
                    SelectionMode = TooltipSelectionMode.SharedYValues
                };

                SolidColorBrush barBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)randomColorGenerator.Next(255), (byte)randomColorGenerator.Next(255), (byte)randomColorGenerator.Next(255)));
                stringBarChart.Series.Add(new RowSeries
                {
                    Title           = "Anzahl",
                    Values          = occurrences,
                    StrokeThickness = 0,
                    Width           = 20,
                    Fill            = barBrush
                });

                stringBarChart.AxisY.Add(new LiveCharts.Wpf.Axis
                {
                    Labels = yAxisValues
                });

                stringBarChart.AxisX.Add(new LiveCharts.Wpf.Axis
                {
                    LabelFormatter = value => value.ToString()
                });

                stringBarChart.DataTooltip = tooltip;
                stringBarChart.Zoom        = ZoomingOptions.Xy;
                stringBarChart.ScrollMode  = ScrollMode.XY;

                #endregion stringBarChart

                #region stringPieChart
                SeriesCollection seriesCollection = new SeriesCollection();

                foreach (KeyValuePair <string, int> keyValuePair in stringListValuePairs)
                {
                    string labelPoint(ChartPoint chartPoint) => string.Format("({0})", keyValuePair.Key);

                    if (!string.IsNullOrWhiteSpace(keyValuePair.Key))
                    {
                        SolidColorBrush pieBrush  = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)randomColorGenerator.Next(255), (byte)randomColorGenerator.Next(255), (byte)randomColorGenerator.Next(255)));
                        PieSeries       pieSeries = new PieSeries
                        {
                            Title  = keyValuePair.Key.ToString(),
                            Values = new ChartValues <double> {
                                keyValuePair.Value
                            },
                            DataLabels      = true,
                            LabelPoint      = labelPoint,
                            StrokeThickness = 0,
                            Fill            = pieBrush
                        };
                        seriesCollection.Add(pieSeries);
                    }
                }
                stringPieChart.LegendLocation = LegendLocation.Bottom;
                stringPieChart.Series         = seriesCollection;
                stringPieChart.Zoom           = ZoomingOptions.Xy;

                #endregion stringPieChart
            }
        }
Esempio n. 9
0
        /// <summary>
        /// The big initializing data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Information_Load(object sender, EventArgs e)
        {
            try
            {
                // Checking the existance of file.
                if (!File.Exists("data.txt"))
                {
                    throw new ArgumentException("There's nothing here. \nAdd graph!");
                }

                var fs = new FileStream("data.txt", FileMode.Open, FileAccess.Read);
                var sr = new StreamReader(fs, Encoding.UTF8);

                while (sr.Peek() > -1)
                {
                    // We set the limit of tabpages to reduce the memory capacity.
                    if (graphTabControl.TabPages.Count > 10)
                    {
                        MessageBox.Show("Limit of Graphs is 10!");
                        break;
                    }
                    // Creating two list for X and Y coords.
                    var axisX = new List <double>();
                    var axisY = new List <double>();
                    // Taking the info from file "data.txt".
                    var dataArray = sr.ReadLine()?.Split('|');
                    // If the first index is Empty, check the next.
                    if (dataArray[0] == String.Empty)
                    {
                        continue;
                    }
                    // Initializing the new datatable
                    DataTable      dt             = CsvTable(dataArray?[0]);
                    OpenFileDialog openFileDialog = new OpenFileDialog {
                        FileName = dataArray?[0]
                    };
                    // Creating the new tabpage.
                    var tabPage = new TabPage
                    {
                        Text = openFileDialog.SafeFileName,
                        AccessibleDescription = dataArray[1]
                    };
                    // Parsing the digits.
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        try
                        {
                            if (double.TryParse(dt.Rows[i].ItemArray[0].ToString(),
                                                NumberStyles.Any, CultureInfo.InvariantCulture, out double num))
                            {
                                axisX.Add(num);
                            }
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        try
                        {
                            if (double.TryParse(dt.Rows[i].ItemArray[1].ToString(),
                                                NumberStyles.Any, CultureInfo.InvariantCulture, out double num))
                            {
                                axisY.Add(num);
                            }
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                    // Check, if data is Chart.
                    if (dataArray[1] == "Chart")
                    {
                        // Creating new object CartesianChart.
                        var cartesianChart = new CartesianChart
                        {
                            Dock           = DockStyle.Fill,
                            Zoom           = ZoomingOptions.X,
                            LegendLocation = LegendLocation.Right
                        };
                        // For color.
                        var gradientBrush = new LinearGradientBrush
                        {
                            StartPoint = new Point(0, 0),
                            EndPoint   = new Point(0, 1)
                        };
                        gradientBrush.GradientStops.Add(new GradientStop(Color.FromRgb(33, 148, 241), 0));
                        gradientBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 1));

                        // Sorting lists.
                        axisX.Sort();
                        axisY.Sort();
                        // Choosing points.
                        var observablePoint = new ChartValues <ObservablePoint>();
                        observablePoint.AddRange(axisX.Select((t, i) =>
                                                              new ObservablePoint(t, axisY[i])).ToList());
                        // It needs to calculate the avg, median,sa and dispress
                        GetInfo(axisX, axisY);
                        // Adding new Series.
                        cartesianChart.Series =
                            new SeriesCollection(Mappers.Xy <ObservablePoint>()
                                                 .X(point => Math.Log10(point.X))
                                                 .Y(point => point.Y))
                        {
                            new LineSeries()
                            {
                                Title           = $"{dt.Columns[0].ColumnName} => {dt.Columns[1].ColumnName}",
                                Values          = observablePoint,
                                DataLabels      = true,
                                Fill            = gradientBrush,
                                StrokeThickness = 1,
                            }
                        };
                        // Creating new panel.
                        Panel panel = new Panel();
                        panel = barPanel;
                        // Adding to control.
                        tabPage.Controls.Add(panel);
                        cartesianChart.DataClick += CartesianChart_DataClick;
                        // Добавляем параметры  в вкладку.
                        tabPage.Controls.Add(cartesianChart);
                    }
                    else
                    {
                        // Creating new object PieChart.
                        var pieChart = new PieChart
                        {
                            Dock = DockStyle.Fill
                        };
                        // Sorting the lists.
                        axisX.Sort();
                        // Adding chart.
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            pieChart.Series.Add(
                                new PieSeries()
                            {
                                Title  = $"{dt.Columns[1].ColumnName}",
                                Values = new ChartValues <double>()
                                {
                                    axisX[i]
                                },
                                DataLabels = true,
                            }
                                );
                        }
                        // Adding second Chart
                        var secondColumn = new CartesianChart()
                        {
                            Dock = DockStyle.Right,
                        };

                        // Initializing it.
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (i == 30)
                            {
                                break;
                            }
                            secondColumn.Series.Add(
                                new ColumnSeries()
                            {
                                Title  = $"{dt.Columns[0].ColumnName}",
                                Values = new ChartValues <double>()
                                {
                                    axisX[i]
                                },
                                DataLabels = true,
                                Width      = 5,
                                Height     = 10
                            }
                                );
                        }
                        // Adding to panels.
                        var firstPanel = new Panel()
                        {
                            Dock = DockStyle.Right,
                            Size = new Size(500, 500),
                        };
                        var secondPanel = new Panel()
                        {
                            Dock         = DockStyle.Left,
                            AutoSize     = true,
                            AutoSizeMode = AutoSizeMode.GrowOnly
                        };
                        // And Adding all of these to tabpage control
                        // + connecting events.
                        firstPanel.Controls.Add(pieChart);
                        secondPanel.Controls.Add(secondColumn);
                        pieChart.DataClick     += PieChart_DataClick;
                        secondColumn.DataClick += ColumnChart_DataClick;

                        // Adding parameters.
                        tabPage.Controls.Add(firstPanel);
                        tabPage.Controls.Add(secondPanel);
                    }
                    graphTabControl.SelectedTab = tabPage;
                    graphTabControl.TabPages.Add(tabPage);

                    var graphChart = graphTabControl.TabPages[graphTabControl.SelectedIndex].Controls[0];
                    graphChart.Select();
                }
                fs.Flush();
                fs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }