public static string TwoDTest() { int[] data = new int[] { 10, 20, 30, 40 }; PieChart pieChart = new PieChart(250, 150); pieChart.SetTitle("2D Test"); pieChart.SetData(data); pieChart.SetPieChartLabels(new string[] { "A", "B", "C", "D" }); return pieChart.GetUrl(); }
public static string ThreeDTest() { int[] data = new int[] { 10, 20, 30, 40 }; PieChart pieChart = new PieChart(300, 150, PieChartType.ThreeD); pieChart.SetTitle("3D Test"); pieChart.SetData(data); pieChart.SetPieChartLabels(new string[] { "A", "B", "C", "D" }); pieChart.SetDatasetColors(new string[] { "0000FF" }); return pieChart.GetUrl(); }
//クエリからGoogleChartを作成 public static void CreateGoogleChart(IEnumerable<ApiShip> queriedShips) { //艦種別に経験値を集計 var summaryexp = new SortedDictionary<int, long>(); foreach(var q in queriedShips) { var shiptype = q.DShip.api_stype; long exp; summaryexp.TryGetValue(shiptype, out exp); exp += q.api_exp != null ? q.api_exp[0] : 0; summaryexp[shiptype] = exp; } //キャラ別に集計するか var isSummariesByChara = summaryexp.Count == 1; if(isSummariesByChara) { summaryexp = new SortedDictionary<int, long>(); foreach(var q in queriedShips) { var ship = q.DShip.api_id; long exp; summaryexp.TryGetValue(ship, out exp); exp += q.api_exp != null ? q.api_exp[0] : 0; summaryexp[ship] = exp; } } //円グラフの割合に変更 var sum = summaryexp.Values.Sum(); if (sum == 0) return; var data = summaryexp.Values.Select(x => (float)(x * 100 / sum)).ToArray(); //ラベル string[] labels; if (isSummariesByChara) { labels = summaryexp.Keys.Select(delegate(int x) { ExMasterShip mstship; if (APIMaster.MstShips.TryGetValue(x, out mstship)) { if (mstship.api_name != null) return mstship.api_name; else return ""; } else return ""; }).ToArray(); } else { labels = summaryexp.Keys.Select(delegate(int x) { ApiMstStype mststype; if (APIMaster.MstStypesDictionary.TryGetValue(x, out mststype)) { if (mststype.api_name != null) { switch(mststype.api_id) { case 8: return "高速戦艦"; case 9: return "低速戦艦"; default: return mststype.api_name; } } else return ""; } else { return ""; } }).ToArray(); } //グラフサイズ var log = Math.Log10(sum)-5;//10^6が最低で1、10^9が最高で4 var ratio = Math.Max(Math.Min(log, 4.0), 1.0);//解像度の倍率 var pixely = (int)(96.0 * ratio); //グラフを作成 var pieChart = new PieChart(pixely * 2, pixely, PieChartType.ThreeD); pieChart.SetTitle(sum.ToString("N0") + " Exp"); pieChart.SetData(data); pieChart.SetPieChartLabels(labels); //色 pieChart.SetDatasetColors(new string[] { "FF66FF", "FFFF66", "66FFFF" }); //URLを取得 var url = pieChart.GetUrl(); Process.Start(url); }