示例#1
0
 private void BtnResetChart_Click(object sender, EventArgs e)
 {
     ChtChart.Series.Clear();
     for (int index = 0; index < ClbCountries.Items.Count; index++)
     {
         ClbCountries.SetItemChecked(index, false);
     }
 }
示例#2
0
        private void AddRemoveChartSeries(int countryIndex)
        {
            string    countryName = countries[countryIndex].Name;
            DataPoint dp;

            if (IsCountrySelected(countryIndex))
            {
                ChtChart.Series.Remove(ChtChart.Series[countryName]);
                ClbCountries.SetItemChecked(countryIndex, false);
            }
            else
            {
                ChtChart.Series.Add(countryName);
                ChtChart.Series[countryName].ChartType = (SeriesChartType)ChartType[CboChartType.SelectedIndex];
                switch (ChtChart.Series[countryName].ChartType)
                {
                case SeriesChartType.Line:
                    ChtChart.Series[countryName].IsVisibleInLegend = false;
                    break;

                default:
                    ChtChart.Series[countryName].IsVisibleInLegend = true;
                    break;
                }

                int  totalCases  = 0;
                int  totalDeaths = 0;
                long population  = countries[countryIndex].Population;
                for (int index = countries[countryIndex].CountryRecords.Count - 1; index >= 0; index--)
                {
                    int    cases  = countries[countryIndex].CountryRecords[index].Cases;
                    int    deaths = countries[countryIndex].CountryRecords[index].Deaths;
                    string date   = countries[countryIndex].CountryRecords[index].Date;
                    totalCases  += cases;
                    totalDeaths += deaths;
                    double yAxisData = 0.0;
                    string dataLabel = "";
                    switch ((ChartData)CboChartDataSet.SelectedIndex)
                    {
                    case ChartData.TotalCasesPerMillionPeople:
                        yAxisData = (double)totalCases / ((double)population / 1000000);
                        dataLabel = "Total Cases Per Million";
                        break;

                    case ChartData.DailyCasesPerMillionPeople:
                        yAxisData = (double)cases / ((double)population / 1000000);
                        dataLabel = "Daily Cases Per Million";
                        break;

                    case ChartData.TotalDeathsPerMillionPeople:
                        yAxisData = (double)totalDeaths / ((double)population / 1000000);
                        dataLabel = "Total Deaths Per Million";
                        break;

                    case ChartData.DailyDeathsPerMillionPeople:
                        yAxisData = (double)deaths / ((double)population / 1000000);
                        dataLabel = "Daily Deaths Per Million";
                        break;

                    case ChartData.TotalCasesByDay:
                        dataLabel = "Total Cases By Day";
                        yAxisData = (double)totalCases;
                        break;

                    case ChartData.DailyCases:
                        dataLabel = "Daily Cases";
                        yAxisData = (double)cases;
                        break;

                    case ChartData.TotalDeathsByDay:
                        yAxisData = (double)totalDeaths;
                        dataLabel = "Total Deaths Per By Day";
                        break;

                    case ChartData.DailyDeaths:
                        yAxisData = (double)deaths;
                        dataLabel = "Daily Deaths";
                        break;
                    }
                    ChtChart.Titles[0].Text = dataLabel;
                    dataLabel += ": " + string.Format("{0:#,0.#}", yAxisData);
                    dp         = new DataPoint();
                    dp.SetValueXY(date, yAxisData);
                    dp.ToolTip = "Date: " + date + Environment.NewLine + dataLabel;
                    ChtChart.Series[countryName].ToolTip = "#VALX, #VAL";
                    ChtChart.Series[countryName].Points.Add(dp);
                    ChtChart.ChartAreas[0].AxisX.IsReversed = false;
                    ChtChart.ChartAreas[0].AxisX.Title      = "Date";
                    ChtChart.ChartAreas[0].AxisY.Title      = "Amount";
                }
                ChtChart.Series[countryName].Points[ChtChart.Series[countryName].Points.Count - 1].Label = countryName;
                ClbCountries.SetItemChecked(countryIndex, true);
            }
        }