Esempio n. 1
0
        /// <summary>
        /// 円グラフ作成(アニメーションありのグラフ)
        /// </summary>
        public void CreateNLivePieChart()
        {
            try
            {
                pChartStatistics.Series = new LiveCharts.SeriesCollection();

                List <StatisticsData> statisticsDataList = GetStatisticsDataList();
                if (statisticsDataList.Count <= 0)
                {
                    return;
                }

                StatisticsSeries = new LiveCharts.SeriesCollection();
                Func <ChartPoint, string> labelPoint = chartPoint => string.Format("{0:#,0}円", chartPoint.Y);

                var totalMoney = statisticsDataList.Select(x => x.Money).Sum();
                //リスト設定
                List <StatisticsListData> statisticsListData = new List <StatisticsListData>();

                foreach (var statisticsData in statisticsDataList)
                {
                    PieSeries pieSeries = new PieSeries
                    {
                        // Title⇒収入と支出の分類を表示
                        Title = statisticsData.Classification,
                        // Values⇒金額を表示
                        Values = new ChartValues <double> {
                            statisticsData.Money
                        },
                        DataLabels = true,
                        LabelPoint = labelPoint
                    };

                    StatisticsSeries.Add(pieSeries);

                    //リスト用のデータ作成
                    StatisticsListData data = new StatisticsListData
                    {
                        Percentage     = (statisticsData.Money / totalMoney * 100).ToString() + "%",
                        Classification = statisticsData.Classification,
                        AmountOfMoney  = statisticsData.Money
                    };
                    statisticsListData.Add(data);
                }

                //円グラフ表示設定
                pChartStatistics.Series                = StatisticsSeries;
                pChartStatistics.LegendLocation        = LegendLocation.Bottom;
                pChartStatistics.StartingRotationAngle = INIT_PIE_ANGLE;

                //リスト表示
                if (!CreateListData(statisticsListData))
                {
                    return;
                }
            }
            catch (Exception e)
            {
                string s = e.Message;
                OriginMBox.MBoxErrorOK(AppConst.SERIES_MESSAGE);
                return;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 円グラフ作成(普通のグラフ)
        /// </summary>
        public void CreatePieChart()
        {
            pChartStatistics2.Series.Clear();
            pChartStatistics2.ChartAreas.Clear();
            pChartStatistics2.Titles.Clear();

            // ChartにChartAreaを追加します
            string chart_area1 = "Area1";

            pChartStatistics2.ChartAreas.Add(new ChartArea(chart_area1));
            // ChartにSeriesを追加します
            string legend1 = "Graph1";

            pChartStatistics2.Series.Add(legend1);
            // グラフの種別を指定
            pChartStatistics2.Series[legend1].ChartType = SeriesChartType.Pie; // 円グラフを指定してみます
            // グラフのタイトルを設定
            if (DTPickerBreakdown02.Visible)
            {
                pChartStatistics2.Titles.Add(DTPickerBreakdown.Value.ToString("yyyy/MM")
                                             + "~" + DTPickerBreakdown02.Value.ToString("yyyy/MM") + "の" + CbClassification.Text + "データ");
            }
            else
            {
                pChartStatistics2.Titles.Add(DTPickerBreakdown.Value.ToString("yyyy/MM")
                                             + "の" + CbClassification.Text + "データ");
            }
            pChartStatistics2.Titles[0].Font = new Font("MS ゴシック", 14, FontStyle.Bold, GraphicsUnit.Point, 128);

            List <StatisticsData> statisticsDataList = GetStatisticsDataList();

            if (statisticsDataList.Count <= 0)
            {
                return;
            }
            var totalMoney    = statisticsDataList.Select(x => x.Money).Sum();
            var moneyList     = statisticsDataList.Select(x => x.Money).ToList();
            var moneyTypeList = statisticsDataList.Select(x => x.Classification).ToList();

            // データをシリーズにセットします
            for (int i = 0; i < moneyList.Count; i++)
            {
                double    rate = (moneyList[i] / totalMoney) * 100.0; // <-- ここで割合を算出します
                DataPoint dp   = new DataPoint
                {
                    Label = moneyTypeList[i]
                };
                dp.SetValueXY(moneyTypeList[i], rate);
                dp.SetCustomProperty("PieLabelStyle", "Disabled");
                pChartStatistics2.Series[legend1].Points.Add(dp);
            }

            //リスト設定
            List <StatisticsListData> statisticsListData = new List <StatisticsListData>();

            foreach (var statisticsData in statisticsDataList)
            {
                //リスト用のデータ作成
                StatisticsListData data = new StatisticsListData
                {
                    Percentage     = (statisticsData.Money / totalMoney * 100).ToString() + "%",
                    Classification = statisticsData.Classification,
                    AmountOfMoney  = statisticsData.Money
                };
                statisticsListData.Add(data);
            }

            statisticsLists = statisticsListData;
            //リスト表示
            if (!CreateListData(statisticsListData))
            {
                return;
            }
        }