public static IList<Pie> GetBrowsersData(int count) { var idx = 1; IList<Pie> pies = new List<Pie>(); for (int i = 0; i < count; i++) { var pie = new Pie("浏览器(数据纯属虚构)"); var pd1 = new PieData<int>(idx * 128 + 80, "Chrome"); var pd2 = new PieData<int>(idx * 64 + 160, "Firefox"); var pd3 = new PieData<int>(idx * 32 + 320, "Safari"); var pd4 = new PieData<int>(idx * 16 + 640, "IE9+"); var pd5 = new PieData<int>(idx++ * 8 + 1280, "IE8-"); pie.Data(pd1, pd2, pd3, pd4, pd5); pies.Add(pie); } return pies; }
private async void button_create_stat_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < stat_chart.Series.Count; i++) { stat_chart.Series.Remove(stat_chart.Series[i]); } values = null; list_pie = new List <PieData>(); List <Orders> list_orders = await oOrdersRepository.Select_All_Orders_Async(); for (int i = 0; i < list_orders.Count; i++) { PieData pd = new PieData(); List <Carts> list_carts = await oCartsRepository.Select_Carts_Async("select count,bouquets_id from Carts where orders_id=" + list_orders[i].orders_id); foreach (var n in list_carts) { pd.count = (int)n.count; pd.bouqet_id = n.bouquets_id; Bouquets b = await conn.GetAsync <Bouquets>(n.bouquets_id); pd.name = b.name; list_pie.Add(pd); } } int min_id = 0; int max = 0; int min = 1000000; int max_id = 0; for (int i = 0; i < list_pie.Count; i++) { if (list_pie[i].count > max) { max = list_pie[i].count; max_id = i; } } for (int i = 0; i < list_pie.Count; i++) { if (list_pie[i].count < min) { min = list_pie[i].count; min_id = i; } } List <Bouquets> list_bouq = await oBouquetsRepository.Select_All_Bouquets_Async(); pie_values = new List <KeyValuePair <string, int> >(); string min_name = ""; string max_name = ""; for (int j = 0; j < list_pie.Count; j++) { if (j == min_id || j == max_id) { pie_values.Add(new KeyValuePair <string, int>(list_pie[j].name, list_pie[j].count)); if (j == min_id) { min_name = list_pie[j].name; } if (j == max_id) { max_name = list_pie[j].name; } } } createPieSeries_Stat(pie_values); button_create_stat.IsEnabled = false; button_excel_stat.IsEnabled = true; }
void SetData(int count, float range) { float mult = range; var yVals1 = new List<Entry>(); // IMPORTANT: In a PieChart, no values (Entry) should have the same // xIndex (even if from different DataSets), since no values can be // drawn above each other. for (int i = 0; i < count + 1; i++) { yVals1.Add(new Entry((float) (new Random().Next() * mult) + mult / 5, i)); } var xVals = new List<String>(); for (int i = 0; i < count + 1; i++) xVals.Add(mParties[i % mParties.Length]); PieDataSet dataSet = new PieDataSet(yVals1, "Election Results"); dataSet.SliceSpace = 2f; dataSet.SelectionShift = 5f; var colors = new List<Java.Lang.Integer>(); foreach (Java.Lang.Integer c in ColorTemplate.VordiplomColors) colors.Add(c); foreach (Java.Lang.Integer c in ColorTemplate.JoyfulColors) colors.Add(c); foreach (Java.Lang.Integer c in ColorTemplate.ColorfulColors) colors.Add(c); foreach (Java.Lang.Integer c in ColorTemplate.LibertyColors) colors.Add(c); foreach (Java.Lang.Integer c in ColorTemplate.PastelColors) colors.Add(c); colors.Add((Java.Lang.Integer)ColorTemplate.HoloBlue); dataSet.Colors = colors; //dataSet.setSelectionShift(0f); PieData data = new PieData(xVals, dataSet); data.SetValueFormatter(new PercentFormatter()); data.SetValueTextSize(11f); data.SetValueTextColor(Color.White); data.SetValueTypeface(tf); mChart.Data = data; // undo all highlights mChart.HighlightValues(null); mChart.Invalidate(); }
public ActionResult ChartView(PieData data) { return(View(data)); }
private void DrawPieChart() { List <PieEntry> datalist = new List <PieEntry>(); int[] colors = new int[14]; for (int i = 0; i < lstPieChartDataValue.Count; i++) { string expensecategory = lstPieChartDataValue[i].ExpenseCategory; double total = lstPieChartDataValue[i].Total; datalist.Add(new PieEntry((float)total, expensecategory)); switch (expensecategory) { case "Food and Dining": colors[i] = Android.Graphics.Color.ParseColor("#FFA500"); break; case "Shopping": colors[i] = Android.Graphics.Color.ParseColor("#40C4FF"); break; case "Travelling": colors[i] = Android.Graphics.Color.ParseColor("#00BFA5"); break; case "Entertainment": colors[i] = Android.Graphics.Color.ParseColor("#e49ef0"); break; case "Medical": colors[i] = Android.Graphics.Color.ParseColor("#FF0000"); break; case "Personal Care": colors[i] = Android.Graphics.Color.ParseColor("#0EDBDB"); break; case "Education": colors[i] = Android.Graphics.Color.ParseColor("#1b49f2"); break; case "Bills and Utilities": colors[i] = Android.Graphics.Color.ParseColor("#006600"); break; case "Banking": colors[i] = Android.Graphics.Color.ParseColor("#FFAB91"); break; case "Rent": colors[i] = Android.Graphics.Color.ParseColor("#9E9D24"); break; case "Taxes": colors[i] = Android.Graphics.Color.ParseColor("#DB32B1"); break; case "Insurance": colors[i] = Android.Graphics.Color.ParseColor("#AA00FF"); break; case "Gifts and Donations": colors[i] = Android.Graphics.Color.ParseColor("#8699E3"); break; case "Other": colors[i] = Android.Graphics.Color.ParseColor("#695e5e"); break; } } prefs = PreferenceManager.GetDefaultSharedPreferences(this); MikePhil.Charting.Data.PieDataSet pieDataSet = new MikePhil.Charting.Data.PieDataSet(datalist, ""); pieDataSet.YValuePosition = PieDataSet.ValuePosition.OutsideSlice; //pieDataSet.ValueLinePart1OffsetPercentage=100f; /** When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size */ pieDataSet.ValueLinePart1Length = 0.4f; /** When valuePosition is OutsideSlice, indicates length of first half of the line */ pieDataSet.ValueLinePart2Length = 0.4f; pieDataSet.SliceSpace = 0.5f; pieDataSet.SelectionShift = 5f; Java.Util.Random rnd = new Java.Util.Random(); //int[] colors = new int[lstExpenseCategories.Count]; //for (int i = 0; i < lstExpenseCategories.Count; i++) //{ // Android.Graphics.Color randomColor = Android.Graphics.Color.Rgb(rnd.NextInt(256), rnd.NextInt(256), rnd.NextInt(256)); // colors[i] = randomColor; //} pieDataSet.SetColors(colors); // pieDataSet.SetColors(PieChartColors.piecharcolors.Take(lstExpenseCategories.Count).ToArray()); // pieDataSet.Colors = ColorTemplate.MaterialColors.Select(c => new Java.Lang.Integer(c)).ToList(); pieDataSet.ValueTextSize = 10f; pieDataSet.ValueTextColor = Android.Graphics.Color.Black; piechartStats.Description.Enabled = false; piechartStats.CenterText = ""; Legend l = piechartStats.Legend; l.VerticalAlignment = Legend.LegendVerticalAlignment.Bottom; l.HorizontalAlignment = Legend.LegendHorizontalAlignment.Left; l.Orientation = Legend.LegendOrientation.Horizontal; l.WordWrapEnabled = true; l.SetDrawInside(false); l.Enabled = true; piechartStats.SetExtraOffsets(0f, 2f, 0f, 2f); piechartStats.SetDrawEntryLabels(false); PieData pieData = new PieData(pieDataSet); piechartStats.Data = pieData; piechartStats.AnimateXY(1000, 1000); piechartStats.Invalidate(); progressBarStats.Visibility = ViewStates.Invisible; piechartStats.Visibility = ViewStates.Visible; statsdata.Visibility = ViewStates.Invisible; generatePDF.Visibility = ViewStates.Visible; statstype.Text = "Total expense for the month" + "(" + SelectedMonth.Substring(0, 3) + ")" + " = " + prefs.GetString("CurrencySymbolSelected", "") + lstPieChartDataValue.Sum(x => Convert.ToDouble(x.Total)); }
private void MyPieChart() { sumOfLowOccupancy = (from table in mListStatsColumns where table.LOW_OCCUPANCY.Contains("YES", StringComparison.OrdinalIgnoreCase) select table).Count(); sumOfHighOccupancy = (from table in mListStatsColumns where table.LOW_OCCUPANCY.Contains("NO", StringComparison.OrdinalIgnoreCase) select table).Count(); resoultHighOccupancy = (sumOfHighOccupancy / sumOfLowOccupancy) * 100; resoultLowOccupncy = (sumOfLowOccupancy / sumOfHighOccupancy) * 100; mListOfEntry = new List <PieEntry>(); mListOfEntry.Add(new PieEntry(resoultHighOccupancy, "High occupancy")); mListOfEntry.Add(new PieEntry(resoultLowOccupncy, "Low occupancy")); dataSet = new PieDataSet(mListOfEntry, ""); dataSet.SliceSpace = 3; dataSet.SelectionShift = 2; dataSet.SetColor(Color.DarkGreen, 200); dataSet.AddColor(Color.DarkRed); PieData data = new PieData(dataSet); data.SetValueFormatter(new PercentFormatter()); data.SetValueTextSize(11f); data.SetValueTextColor(Color.Black); mPieChart.Data = data; mPieChart.HighlightValues(null); mPieChart.SetUsePercentValues(true); mPieChart.Description.Enabled = false; mPieChart.SetExtraOffsets(5, 10, 5, 5); mPieChart.DrawHoleEnabled = true; mPieChart.SetHoleColor(Color.White); mPieChart.HoleRadius = 7; mPieChart.SetTransparentCircleAlpha(10); mPieChart.RotationAngle = 0; mPieChart.RotationEnabled = true; mPieChart.HighlightPerTapEnabled = true; mPieChart.AnimateY(2000, Easing.EasingOption.EaseInOutQuad); Legend legend = mPieChart.Legend; legend.Position = Legend.LegendPosition.RightOfChart; legend.XEntrySpace = 7; legend.YEntrySpace = 5; mPieChart.Invalidate(); }
private void SetChartData() { var chart = FindViewById <PieChart>(Resource.Id.chart); chart.RotationAngle = 0; chart.RotationEnabled = true; chart.HighlightPerTapEnabled = false; chart.SetUsePercentValues(true); chart.Description.Enabled = false; chart.SetExtraOffsets(5, 10, 5, 5); chart.DrawHoleEnabled = true; chart.SetHoleColor(Color.Transparent); chart.HoleRadius = 7f; chart.AnimateY(1400, Easing.EasingOption.EaseInOutQuad); var entries = new List <PieEntry>(); var values = ViewModel.StatisticItems.Select(x => x.Value).ToList(); var labels = ViewModel.StatisticItems.Select(x => x.Label).ToList(); for (int i = 0; i < values.Count; i++) { entries.Add(new PieEntry((float)values[i], labels[i])); } var dataSet = new PieDataSet(entries, "") { SliceSpace = 1f }; dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading1, Theme)); dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading2, Theme)); dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading3, Theme)); dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading4, Theme)); dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading5, Theme)); dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading6, Theme)); dataSet.AddColor(Resources.GetColor(Resource.Color.color_spreading7, Theme)); var data = new PieData(dataSet); data.SetValueFormatter(new PercentFormatter()); data.SetValueTextSize(11f); data.SetValueTextColor(Color.White); chart.SetDrawEntryLabels(false); chart.Data = data; var legend = chart.Legend; legend.TextSize = 12f; legend.Orientation = Legend.LegendOrientation.Vertical; legend.SetDrawInside(false); legend.VerticalAlignment = Legend.LegendVerticalAlignment.Top; legend.HorizontalAlignment = Legend.LegendHorizontalAlignment.Left; legend.XEntrySpace = 7f; legend.YEntrySpace = 0; legend.YOffset = 0f; chart.HighlightValues(null); chart.Invalidate(); }
private void popList1_Selected(object sender, EventArgs e) { switch (popList1.Selections[0].Text) { case "DataBind": DataBind(); break; case "Legend": this.pieChart1.Legend.XEntrySpace = 10; this.pieChart1.Legend.YEntrySpace = 10; this.pieChart1.Legend.Position = LegendPosition.BELOW_CHART_LEFT; this.pieChart1.Legend.XOffset = 1; this.pieChart1.Legend.YOffset = 1; this.pieChart1.Legend.TextSize = 15; this.pieChart1.Legend.TextColor = System.Drawing.Color.Red; break; case "LegendSize": if (this.pieChart1.Legend.Size == 0) { this.pieChart1.Legend.Size = 10; } else { this.pieChart1.Legend.Size = 0; } break; case "AddSet": this.pieChart1.Data.AddSeries(GetNewSerie(this.pieChart1.Data)); break; case "RemoveSet": if (this.pieChart1.Data.SeriesCount > 0) { this.pieChart1.Data.RemoveSeries(0); } break; case "ClearSet": this.pieChart1.Data.ClearValues(); break; case "SetData": List <string> xLabels = new List <string>(); xLabels.AddRange(new string[] { "1", "2", "3", "4" }); PieData data = new PieData(xLabels); ChartYAxisValueCollection <ChartYAxisValue> yVals = new ChartYAxisValueCollection <ChartYAxisValue>(); yVals.Add(new BarYAxisValue(1111111)); yVals.Add(new BarYAxisValue(3333333)); yVals.Add(new BarYAxisValue(666666666666)); yVals.Add(new BarYAxisValue(333333333333)); PieSeries set1 = new PieSeries(yVals, "DataSet 1"); set1.AddColor(DemoGlobal.GetRandomColor()); set1.AddColor(DemoGlobal.GetRandomColor()); set1.AddColor(DemoGlobal.GetRandomColor()); data.AddSeries(set1); this.pieChart1.Data = data; break; } }
public static string GetOrderType(string dataType, DateTime BgTime, DateTime EdTime) { FusionPieModel model = new FusionPieModel(); string strJson = ""; DateTime bgTime = new DateTime(); DateTime edTime = new DateTime(); if (dataType == "oth") { bgTime = BgTime; edTime = EdTime.AddHours(23).AddMinutes(59).AddSeconds(59); } else if (dataType == "month") { DateTime FirstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); DateTime LastDay = FirstDay.AddMonths(1).AddDays(-1); bgTime = FirstDay; edTime = LastDay.AddHours(23).AddMinutes(59).AddSeconds(59); } else if (dataType == "lastmonth") { DateTime nowTime = DateTime.Now.AddMonths(-1); DateTime FirstDay = new DateTime(nowTime.Year, nowTime.Month, 1); DateTime LastDay = FirstDay.AddMonths(1).AddDays(-1); bgTime = FirstDay; edTime = LastDay.AddHours(23).AddMinutes(59).AddSeconds(59); } else if (dataType == "3month") { DateTime nowTime = DateTime.Now.AddMonths(-2); DateTime FirstDay = new DateTime(nowTime.Year, nowTime.Month, 1); DateTime LastDay = FirstDay.AddMonths(3).AddDays(-1); bgTime = FirstDay; edTime = LastDay.AddHours(23).AddMinutes(59).AddSeconds(59); } else if (dataType == "today") { bgTime = DateTime.Today.AddHours(0).AddMinutes(0).AddSeconds(0); edTime = DateTime.Today.AddHours(23).AddMinutes(59).AddSeconds(59); } List <OrderInfoModel> list = T_OrderInfoBLL.GetOrderInfoByDate(bgTime, edTime, 0); double self = 0; double other = 0; double otherServ = 0; //int count = 0;//调试信息 foreach (var item in list) { OrderItemProp tempModel = T_Order_businessBLL.GetListItemProps(Convert.ToInt32(item.busId), item.accId); if (tempModel.SelfMark == "1") { self += Convert.ToDouble(item.RealPayMoney); } else if (tempModel.PureSms == "1") { otherServ += Convert.ToDouble(item.RealPayMoney); //count++; } else { other += Convert.ToDouble(item.RealPayMoney); } } //获取实物商品相关统计(实物商品计入他营产品) List <OrderInfoModel> MaterialList = T_OrderInfoBLL.GetOrderInfoByDate(bgTime, edTime, 1); if (MaterialList != null && MaterialList.Count > 0) { foreach (var item in MaterialList) { other += Convert.ToDouble(item.RealPayMoney); } } //获取京东订单那相关统计(订单商品计入他营产品) List <OrderInfoModel> JdList = T_OrderInfoBLL.GetOrderInfoByDate(bgTime, edTime, 2); if (MaterialList != null && MaterialList.Count > 0) { foreach (var item in MaterialList) { other += Convert.ToDouble(item.RealPayMoney); } } //OrderPartition orderMoney = T_OrderInfoBLL.GetOrderType(bgTime, edTime); double allMoney = self + other + otherServ; model.chart.caption = "产品类型比例"; model.chart.baseFontSize = "12"; model.chart.showpercentvalues = "1"; PieData servData = new PieData(); servData.label = "第三方服务"; servData.value = GetBaiFen(Convert.ToDouble(otherServ), allMoney); servData.toolText = "第三方服务," + GetBaiFen(Convert.ToDouble(otherServ), allMoney) + "% (¥" + ControlHelper.formats(otherServ, 2).ToString() + ")"; model.data.Add(servData); PieData selfData = new PieData(); selfData.label = "Saas服务"; selfData.value = GetBaiFen(Convert.ToDouble(self), allMoney); selfData.toolText = "Saas服务," + GetBaiFen(Convert.ToDouble(self), allMoney) + "% (¥" + ControlHelper.formats(self, 2).ToString() + ")"; model.data.Add(selfData); PieData otherData = new PieData(); otherData.label = "他营"; otherData.value = GetBaiFen(Convert.ToDouble(other), allMoney); otherData.toolText = "他营," + GetBaiFen(Convert.ToDouble(other), allMoney) + "% (¥" + ControlHelper.formats(other, 2).ToString() + ")"; model.data.Add(otherData); return(CommonLib.Helper.JsonSerializeObject(model)); }
private View CreateUserListStatusView(IReadOnlyList <AniListStatusDistribution> statusDistribution) { var detailView = LayoutInflater.Inflate(Resource.Layout.View_AniListObjectDetail, null); var detailContainer = detailView.FindViewById <LinearLayout>(Resource.Id.AniListObjectDetail_InnerContainer); detailView.FindViewById <TextView>(Resource.Id.AniListObjectDetail_Name).Text = "User Lists"; detailContainer.Orientation = Orientation.Horizontal; var chartHeight = Resources.GetDimensionPixelSize(Resource.Dimension.Details_ChartHeight); var legendMargin = Resources.GetDimensionPixelSize(Resource.Dimension.Details_MarginSmall); var chartContainer = new LinearLayout(this) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, chartHeight, 1) }; var legendContainer = new LinearLayout(this) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, chartHeight, 1) { RightMargin = legendMargin, LeftMargin = legendMargin }, Orientation = Orientation.Vertical }; var typedColorArray = Resources.ObtainTypedArray(Resource.Array.Chart_Colors); var colorList = new List <int>(); for (var i = 0; i < typedColorArray.Length(); i++) { colorList.Add(typedColorArray.GetColor(i, 0)); } var statusChart = new PieChart(this) { LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) }; var slices = statusDistribution.Select(x => new PieEntry(x.Amount, x.Status.DisplayValue) { Data = x.Status.DisplayValue }).ToList(); var dataSet = new PieDataSet(slices, "Status") { SliceSpace = 1, }; dataSet.SetDrawValues(false); dataSet.SetColors(colorList.ToArray(), 255); var data = new PieData(dataSet); statusChart.TransparentCircleRadius = 0; statusChart.HoleRadius = 0; statusChart.Data = data; statusChart.SetDrawEntryLabels(false); statusChart.Description.Enabled = false; statusChart.Legend.Enabled = false; statusChart.RotationEnabled = false; chartContainer.AddView(statusChart); for (var i = 0; i < statusDistribution.Count; i++) { var cell = LayoutInflater.Inflate(Resource.Layout.View_ChartLegendCell, legendContainer, false); var status = statusDistribution[i]; cell.SetBackgroundColor(new Color(colorList[i % 10])); cell.FindViewById <TextView>(Resource.Id.ChartLegendCell_Count).Text = status.Amount.ToTruncatedString(); cell.FindViewById <TextView>(Resource.Id.ChartLegendCell_Text).Text = status.Status.DisplayValue; cell.Tag = status.Status.DisplayValue; legendContainer.AddView(cell); } detailContainer.AddView(chartContainer); detailContainer.AddView(legendContainer); return(detailView); }