private void Page_Load(object sender, System.EventArgs e) { _questionId = Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1; _filterId = Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1; _sortOrder = Request["SortOrder"] == null ? "ans" : Request["SortOrder"]; if (_questionId == -1) { Response.End(); } else if (!NSurveyUser.Identity.IsAdmin && !NSurveyUser.Identity.HasAllSurveyAccess) { if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId)) { Response.End(); } } ChartEngine engine = new ChartEngine(); ChartCollection charts = new ChartCollection(engine); engine.Size = new Size(700, 500); engine.Charts = charts; WebChart.ColumnChart chart = new WebChart.ColumnChart(); chart.Fill.Color = Color.FromArgb(98, 94, 238); chart.MaxColumnWidth = 80; chart.DataLabels.Visible = true; chart.DataLabels.Position = DataLabelPosition.Bottom; chart.DataLabels.ForeColor = Color.White; chart.Shadow.Visible = true; chart.DataLabels.NumberFormat = "0.00"; chart.ShowLineMarkers = true; SetQuestionData(engine, chart); SetMoreProperties(engine); charts.Add(chart); // send chart to browser Bitmap bmp; System.IO.MemoryStream memStream = new System.IO.MemoryStream(); bmp = engine.GetBitmap(); bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); memStream.WriteTo(Response.OutputStream); Response.End(); }
private void Page_Load(object sender, System.EventArgs e) { _questionId = Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1; _filterId = Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1; _sortOrder = Request["SortOrder"] == null ? "ans" : Request["SortOrder"]; if (_questionId == -1) { Response.End(); } else if (!NSurveyUser.Identity.IsAdmin && !NSurveyUser.Identity.HasAllSurveyAccess) { if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId)) { Response.End(); } } ChartEngine engine = new ChartEngine(); ChartCollection charts = new ChartCollection(engine); engine.Size = new Size(700, 500); engine.Charts = charts; PieChart pie = new PieChart(); //pie.Colors = new Color[]{ Color.Red}; ChartLegend legend = new ChartLegend(); legend.Position = LegendPosition.Right; legend.Width = 200; legend.Background.Color = Color.FromArgb(245, 249, 251); pie.DataLabels.NumberFormat = "0.00"; pie.Explosion = 6; pie.Shadow.Visible = true; pie.Shadow.Color = Color.LightGray; pie.Shadow.OffsetY = 5; engine.HasChartLegend = true; engine.Legend = legend; engine.GridLines = GridLines.None; SetQuestionData(engine, pie); SetMoreProperties(engine); charts.Add(pie); // send chart to browser Bitmap bmp; System.IO.MemoryStream memStream = new System.IO.MemoryStream(); bmp = engine.GetBitmap(); bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); memStream.WriteTo(Response.OutputStream); Response.End(); }
public override TransitPicture GetPictureWithBitmap(int id) { ChartEngine engine = new ChartEngine(); engine.Size = new Size(570, 300); engine.GridLines = WebChart.GridLines.None; engine.ShowXValues = true; engine.ShowYValues = true; engine.LeftChartPadding = 50; engine.BottomChartPadding = 50; engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center; engine.XAxisFont.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical; engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black; ChartCollection charts = new ChartCollection(engine); engine.Charts = charts; List <List <TransitSummarizedCounter> > counters = new List <List <TransitSummarizedCounter> >(); string format; string title = RequestType.ToString(); switch (RequestType) { case ChartType.DailyNew: counters.Add(Summary.NewDaily); format = "MMM d"; title = "New Daily"; break; case ChartType.DailyReturning: counters.Add(Summary.ReturningDaily); format = "MMM d"; title = "Returning Daily"; break; case ChartType.Daily: counters.Add(Summary.Daily); format = "MMM d"; break; case ChartType.Hourly: counters.Add(Summary.Hourly); format = "htt"; break; case ChartType.MonthlyUnique: counters.Add(Summary.UniqueMonthly); format = "MMM"; title = "Monthly Unique"; break; case ChartType.Monthly: counters.Add(Summary.Monthly); format = "MMM"; break; case ChartType.Weekly: counters.Add(Summary.Weekly); format = "MMM dd"; break; case ChartType.Yearly: counters.Add(Summary.Yearly); format = "yyyy"; break; case ChartType.AccountDaily: counters.Add(Summary.AccountDaily); format = "MMM d"; title = "New Daily"; break; case ChartType.AccountMonthly: counters.Add(Summary.AccountMonthly); format = "MMM"; title = "New Monthly"; break; case ChartType.AccountWeekly: counters.Add(Summary.AccountWeekly); format = "MMM dd"; title = "New Weekly"; break; case ChartType.AccountYearly: counters.Add(Summary.AccountYearly); format = "yyyy"; title = "New Yearly"; break; default: throw new ArgumentOutOfRangeException("type"); } long total = 0; long count = 0; Color fill = Color.FromArgb(0x9F, 0x6, 0x15); foreach (List <TransitSummarizedCounter> clist in counters) { ColumnChart chart = new ColumnChart(); chart.ShowLineMarkers = false; chart.ShowLegend = true; chart.Line.Color = Color.White; chart.Line.Width = 2; chart.Fill.Color = engine.Border.Color = fill; chart.Fill.LinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.Vertical; chart.MaxColumnWidth = 100; count += clist.Count; foreach (TransitSummarizedCounter counter in clist) { total += counter.Total; chart.Data.Add(new ChartPoint(counter.Timestamp.ToString(format), counter.Total)); } charts.Add(chart); fill = Color.FromArgb(fill.R + 0x30, fill.G + 0x30, fill.B + 0x30); } engine.Title = new ChartText(); double average = count > 0 ? total / count : 0; engine.Title.Text = string.Format("{0} (average: {1})", RequestType, average); TransitPicture picture = new TransitPicture(); picture.Id = 0; picture.Modified = picture.Created = DateTime.UtcNow; picture.Name = RequestType.ToString(); MemoryStream ds = new MemoryStream(); engine.GetBitmap().Save(ds, System.Drawing.Imaging.ImageFormat.Png); picture.Bitmap = new byte[ds.Length]; MemoryStream ms = new MemoryStream(picture.Bitmap); ds.WriteTo(ms); return(picture); }
protected void Page_Load(object sender, EventArgs e) { string[] s = new string[2] { "No data", "0" }; if (Request.QueryString["data"] != null) { s = Request.QueryString["data"].Split('|'); } ChartEngine wcEng = new ChartEngine(); if (Request.QueryString["size"] != null) { string[] size = Request.QueryString["size"].Split('|'); wcEng.Size = new Size(Convert.ToInt32(size[0]), Convert.ToInt32(size[1])); } else { wcEng.Size = new Size(400, 400); } ChartCollection wcCharts = new ChartCollection(wcEng); wcEng.Charts = wcCharts; wcEng.RenderHorizontally = false; wcEng.Border.Color = Color.FromArgb(99, Color.SteelBlue); wcEng.ShowXValues = true; wcEng.ShowYValues = true; wcEng.ChartPadding = 30; wcEng.Padding = 0; wcEng.TopPadding = 0; ColumnChart chart = new ColumnChart(); chart.Shadow.Visible = false; chart.MaxColumnWidth = Convert.ToInt32(wcEng.Size.Height / s.Length); chart.Fill.Color = Color.FromArgb(90, Color.SteelBlue); chart.Line.Color = Color.SteelBlue; chart.Line.Width = 2; chart.DataLabels.Visible = true; chart.DataLabels.ShowValue = true; for (int i = 0; i < s.Length; i++) { ChartPoint cp = new ChartPoint(); cp.XValue = s[i]; cp.YValue = Convert.ToInt32(s[i + 1]); chart.Data.Add(cp); i += 1; } wcCharts.Add(chart); MemoryStream memStream = new MemoryStream(); Bitmap bmp = wcEng.GetBitmap(); Graphics g = Graphics.FromImage(bmp); Pen mypen = new Pen(Color.Black, 1F); g.DrawRectangle(mypen, 0, 0, bmp.Width - 1, bmp.Height - 1); bmp.Save(memStream, ImageFormat.Png); memStream.WriteTo(Response.OutputStream); Response.ContentType = "image/png"; Response.End(); }
private void RenderUsers() { //Session["chart_ids"] = ids; //Session["chart_names"] = names; try { string[] ids_arr; string[] names_arr; ids_arr = Session["chart_ids"].ToString().Split('^'); names_arr = Session["chart_names"].ToString().Split('^'); DataSet dsUsers = new DataSet("UsersDS"); dsUsers.Tables.Add("Users"); DataTable dt = dsUsers.Tables["Users"]; dt.Columns.Add("Id"); dt.Columns.Add("Name"); for(int i =0;i<ids_arr.GetUpperBound(0);i++) { if( ids_arr[i] != "") { DataRow dr; dr = dsUsers.Tables["Users"].NewRow(); dr["Id"] = ids_arr[i]; dr["Name"] = names_arr[i]; dsUsers.Tables["Users"].Rows.Add(dr); } } wcEng = new ChartEngine(); ChartCollection wcCharts = new ChartCollection(wcEng); wcEng.Charts = wcCharts; SetProperties(ref wcEng); DataSet dsXGames = new DataSet("XGames"); FillXGames(ref dsXGames); int n = 0; DataSet dsUserPos = new DataSet("UserPos"); foreach(DataRow dri in dsUsers.Tables["Users"].Rows) { FillUserPos(ref dsUserPos,Convert.ToInt32(dri["id"])); Chart lch = new WebChart.SmoothLineChart(); bool bNeedToShift = false; //foreach (DataRow drxg in dsXGames.Tables[0].Rows) //{ // if (dsUserPos.Tables[0].Rows.Contains(drxg[0])) // { // DataRow drup = dsUserPos.Tables[0].Rows.Find(drxg[0]); // lch.Data.Add(new ChartPoint(ShiftGameName(drxg[0].ToString(), bNeedToShift), Convert.ToSingle(drup[1]))); // } // else // { // DataRow drup = dsUserPos.Tables[0].Rows.Find(drxg[0]); // lch.Data.Add(new ChartPoint(ShiftGameName(drxg[0].ToString(), bNeedToShift), 30)); // } // lch.DataLabels.Visible = true; // lch.DataLabels.ForeColor = Color.LightGray; // //bNeedToShift = !bNeedToShift; //} int nRowCount = dsXGames.Tables[0].Rows.Count; //for(int z=nRowCount;z==1;z--) for (int z = nRowCount - 1; z >= 0; z = z - 1) //DataRow drxg in dsXGames.Tables[0].Rows) { DataRow drxg = dsXGames.Tables[0].Rows[z]; if (dsUserPos.Tables[0].Rows.Contains(drxg[0])) { DataRow drup = dsUserPos.Tables[0].Rows.Find(drxg[0]); lch.Data.Add(new ChartPoint(ShiftGameName(drxg[0].ToString(), bNeedToShift), Convert.ToSingle(drup[1]))); } else { //DataRow drup = dsUserPos.Tables[0].Rows.Find(drxg[0]); //lch.Data.Add(new ChartPoint(ShiftGameName(drxg[0].ToString(), bNeedToShift), -1)); } lch.DataLabels.Visible = true; lch.DataLabels.ForeColor = Color.LightGray; //bNeedToShift = !bNeedToShift; } lch.Line.Color = user_color[n%10]; n++; lch.DataLabels.Visible=true; Font dlFont = new Font("verdana",5); lch.DataLabels.Font = dlFont; lch.Legend = dri["name"].ToString(); lch.DataLabels.ForeColor = Color.Black; lch.LineMarker = new CircleLineMarker(3, lch.Line.Color, lch.Line.Color); wcEng.YCustomEnd = Convert.ToInt32(Session["chart_Ycount"]); wcEng.Charts.Add(lch); } Bitmap bmp; System.IO.MemoryStream memStream = new System.IO.MemoryStream(); bmp = wcEng.GetBitmap(); bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); memStream.WriteTo(Response.OutputStream); Response.End(); } catch (Exception exc) { Response.Write(exc.Message); } }
private void Page_Load(object sender, System.EventArgs e) { _questionId = Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1; _filterId = Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1; _sortOrder = Request["SortOrder"] == null ? "ans" : Request["SortOrder"]; if (_questionId == -1) { Response.End(); } else if (!NSurveyUser.Identity.IsAdmin && !NSurveyUser.Identity.HasAllSurveyAccess) { if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId)) { Response.End(); } } ChartEngine engine = new ChartEngine(); ChartCollection charts = new ChartCollection(engine); engine.Size = new Size(700, 500); engine.Charts = charts; PieChart pie = new PieChart(); //pie.Colors = new Color[]{ Color.Red}; ChartLegend legend = new ChartLegend(); legend.Position = LegendPosition.Right; legend.Width = 200; legend.Background.Color = Color.FromArgb(245,249,251); pie.DataLabels.NumberFormat ="0.00"; pie.Explosion = 6; pie.Shadow.Visible = true; pie.Shadow.Color=Color.LightGray; pie.Shadow.OffsetY = 5; engine.HasChartLegend = true; engine.Legend = legend; engine.GridLines = GridLines.None; SetQuestionData(engine, pie); SetMoreProperties(engine); charts.Add(pie); // send chart to browser Bitmap bmp; System.IO.MemoryStream memStream = new System.IO.MemoryStream(); bmp = engine.GetBitmap(); bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); memStream.WriteTo(Response.OutputStream); Response.End(); }
public void LoadGraph() { ChartEngine tempChartEngine = new ChartEngine(); tempChartEngine.Size = GraphPictureBox.Size; tempChartEngine.ShowXValues = true; tempChartEngine.ShowYValues = true; // tempChartEngine.Padding = 40; tempChartEngine.BottomChartPadding = 30; tempChartEngine.LeftChartPadding = 40; ChartText tempChartText = new ChartText(); tempChartText.Text = "Hourly Sales"; tempChartEngine.Title = tempChartText; CPaymentManager tempPaymentManager = new CPaymentManager(); CResult oResult = tempPaymentManager.GetSortedPayment(DateTime.Now); double MaxAmount = 0.0; if (oResult.IsSuccess && oResult.Data != null) { MaxAmount = (double)oResult.Data; } // tempChartEngine.YValuesInterval = (int)Math.Floor(MaxAmount / 20); tempChartEngine.YValuesInterval = GetInterVal(MaxAmount); tempChartEngine.YCustomEnd = GetCustomEnd(GetInterVal(MaxAmount), MaxAmount); ChartCollection tempChartCollection = new ChartCollection(tempChartEngine); tempChartEngine.Charts = tempChartCollection; DateTime inCurrentDate = DateTime.Now; GetTimeSpan(inCurrentDate); //Data Access try { CPcInfoManager tempPcInfoManager = new CPcInfoManager(); IPHostEntry ipEntry = System.Net.Dns.GetHostByName(Dns.GetHostName()); CPcInfo tempPcInfo = (CPcInfo)tempPcInfoManager.PcInfoByPcIP(ipEntry.AddressList[0].ToString()).Data; DataSet tempHourlySaleDataSet = new DataSet(); CCommonConstants oConstants = ConfigManager.GetConfig<CCommonConstants>(); String sSql = String.Format("select 'NewTime' as \"NewTime\",bill_print_time.payment_time as \"Time\",payment.total_amount as \"Amount\" from payment,bill_print_time where payment.order_id=bill_print_time.order_id and bill_print_time.payment_time>={0} and bill_print_time.payment_time<{1} and payment.pc_id={2}", m_oStartTime, m_oEndTime, tempPcInfo.PcID); SqlDataAdapter tempSqlDataAdapter = new SqlDataAdapter(sSql, oConstants.DBConnection); tempSqlDataAdapter.Fill(tempHourlySaleDataSet); sSql = String.Format("select 'NewTime' as \"NewTime\",deposit_time as \"Time\",total_amount as \"Amount\" from deposit where deposit_time >= {0} and deposit_time < {1} and deposit.pc_id={2}", m_oStartTime, m_oEndTime, tempPcInfo.PcID); tempSqlDataAdapter = new SqlDataAdapter(sSql, oConstants.DBConnection); tempSqlDataAdapter.Fill(tempHourlySaleDataSet); ConvertTime(ref tempHourlySaleDataSet); //start dummy time DataRow row1 = tempHourlySaleDataSet.Tables[0].NewRow(); row1["NewTime"] = "0:00"; row1["Amount"] = "0.000"; //end dummy time DataRow row2 = tempHourlySaleDataSet.Tables[0].NewRow(); row2["NewTime"] = "23:59"; row2["Amount"] = "0.000"; tempHourlySaleDataSet.Tables[0].Rows.Add(row1); tempHourlySaleDataSet.Tables[0].Rows.Add(row2); Chart tempLineChart = new LineChart(); tempLineChart.Line.Color = Color.Red; tempLineChart.ShowLineMarkers = false; tempLineChart.Line.Width = (float)2.0; DataTableReader oReader = tempHourlySaleDataSet.Tables[0].CreateDataReader(); tempLineChart.DataSource = oReader; tempLineChart.DataXValueField = "NewTime"; tempLineChart.DataYValueField = "Amount"; tempLineChart.DataBind(); tempChartCollection.Add(tempLineChart); Image image = tempChartEngine.GetBitmap(); GraphPictureBox.Image = image; GraphPictureBox.Update(); } catch (Exception exp) { throw exp; } }
public override PicturePage.Picture GetPictureWithBitmap(int id) { ChartEngine engine = new ChartEngine(); engine.Size = new Size(570, 300); engine.GridLines = WebChart.GridLines.None; engine.ShowXValues = true; engine.ShowYValues = true; engine.LeftChartPadding = 50; engine.BottomChartPadding = 50; engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center; engine.XAxisFont.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical; engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black; ChartCollection charts = new ChartCollection(engine); engine.Charts = charts; List <TransitCounter> counters = SessionManager.GetCachedCollection <TransitCounter>( "GetStatsSummary", SessionManager.Ticket, new TransitStatsQueryOptions(RequestType)); string format; switch (RequestType) { case TransitStats.Type.Daily: format = "MMM d"; break; case TransitStats.Type.Hourly: format = "htt"; break; case TransitStats.Type.Monthly: format = "MMM"; break; case TransitStats.Type.Weekly: format = "MMM dd"; break; case TransitStats.Type.Yearly: format = "yyyy"; break; default: throw new ArgumentOutOfRangeException("type"); } Color fill = Color.Black; ColumnChart chart = new ColumnChart(); chart.ShowLineMarkers = false; chart.ShowLegend = true; chart.Line.Color = Color.White; chart.Line.Width = 2; chart.Fill.Color = engine.Border.Color = fill; chart.Fill.LinearGradientMode = LinearGradientMode.Vertical; chart.MaxColumnWidth = 100; foreach (TransitCounter counter in counters) { chart.Data.Add(new ChartPoint(counter.Created.ToString(format), counter.Count)); } charts.Add(chart); PicturePage.Picture picture = new PicturePage.Picture(); picture.Id = 0; picture.Modified = DateTime.UtcNow; picture.Name = RequestType.ToString(); MemoryStream ds = new MemoryStream(); engine.GetBitmap().Save(ds, ImageFormat.Png); picture.Bitmap = new byte[ds.Length]; MemoryStream ms = new MemoryStream(picture.Bitmap); ds.WriteTo(ms); return(picture); }
public override TransitPicture GetPictureWithBitmap(int id) { ChartEngine engine = new ChartEngine(); engine.Size = new Size(570, 300); engine.GridLines = WebChart.GridLines.None; engine.ShowXValues = true; engine.ShowYValues = true; engine.LeftChartPadding = 50; engine.BottomChartPadding = 50; engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center; engine.XAxisFont.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical; engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black; ChartCollection charts = new ChartCollection(engine); engine.Charts = charts; List<List<TransitSummarizedCounter>> counters = new List<List<TransitSummarizedCounter>>(); string format; string title = RequestType.ToString(); switch (RequestType) { case ChartType.DailyNew: counters.Add(Summary.NewDaily); format = "MMM d"; title = "New Daily"; break; case ChartType.DailyReturning: counters.Add(Summary.ReturningDaily); format = "MMM d"; title = "Returning Daily"; break; case ChartType.Daily: counters.Add(Summary.Daily); format = "MMM d"; break; case ChartType.Hourly: counters.Add(Summary.Hourly); format = "htt"; break; case ChartType.MonthlyUnique: counters.Add(Summary.UniqueMonthly); format = "MMM"; title = "Monthly Unique"; break; case ChartType.Monthly: counters.Add(Summary.Monthly); format = "MMM"; break; case ChartType.Weekly: counters.Add(Summary.Weekly); format = "MMM dd"; break; case ChartType.Yearly: counters.Add(Summary.Yearly); format = "yyyy"; break; case ChartType.AccountDaily: counters.Add(Summary.AccountDaily); format = "MMM d"; title = "New Daily"; break; case ChartType.AccountMonthly: counters.Add(Summary.AccountMonthly); format = "MMM"; title = "New Monthly"; break; case ChartType.AccountWeekly: counters.Add(Summary.AccountWeekly); format = "MMM dd"; title = "New Weekly"; break; case ChartType.AccountYearly: counters.Add(Summary.AccountYearly); format = "yyyy"; title = "New Yearly"; break; default: throw new ArgumentOutOfRangeException("type"); } long total = 0; long count = 0; Color fill = Color.FromArgb(0x9F, 0x6, 0x15); foreach (List<TransitSummarizedCounter> clist in counters) { ColumnChart chart = new ColumnChart(); chart.ShowLineMarkers = false; chart.ShowLegend = true; chart.Line.Color = Color.White; chart.Line.Width = 2; chart.Fill.Color = engine.Border.Color = fill; chart.Fill.LinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.Vertical; chart.MaxColumnWidth = 100; count += clist.Count; foreach (TransitSummarizedCounter counter in clist) { total += counter.Total; chart.Data.Add(new ChartPoint(counter.Timestamp.ToString(format), counter.Total)); } charts.Add(chart); fill = Color.FromArgb(fill.R + 0x30, fill.G + 0x30, fill.B + 0x30); } engine.Title = new ChartText(); double average = count > 0 ? total / count : 0; engine.Title.Text = string.Format("{0} (average: {1})", RequestType, average); TransitPicture picture = new TransitPicture(); picture.Id = 0; picture.Modified = picture.Created = DateTime.UtcNow; picture.Name = RequestType.ToString(); MemoryStream ds = new MemoryStream(); engine.GetBitmap().Save(ds, System.Drawing.Imaging.ImageFormat.Png); picture.Bitmap = new byte[ds.Length]; MemoryStream ms = new MemoryStream(picture.Bitmap); ds.WriteTo(ms); return picture; }
protected void Page_Load(object sender, EventArgs e) { string[] s = new string[2] { "No data", "1" }; if (Request.QueryString["data"] != null) { s = Request.QueryString["data"].Split('|'); } ChartEngine wcEng = new ChartEngine(); if (Request.QueryString["size"] != null) { string[] size = Request.QueryString["size"].Split('|'); wcEng.Size = new Size(Convert.ToInt32(size[0]), Convert.ToInt32(size[1])); } else { wcEng.Size = new Size(400, 400); } wcEng.GridLines = GridLines.None; wcEng.Padding = 0; wcEng.TopPadding = 0; ChartCollection wcCharts = new ChartCollection(wcEng); wcEng.Charts = wcCharts; PieChart slChart = new MyPieChart(); slChart.Line.Color = Color.Black; slChart.DataLabels.Visible = true; slChart.DataLabels.ShowXTitle = true; slChart.DataLabels.ShowValue = false; slChart.DataLabels.ShowLegend = false; slChart.Shadow.Visible = true; slChart.Explosion = 8; for (int i = 0; i < s.Length; i++) { ChartPoint cp = new ChartPoint(); cp.XValue = s[i]; cp.YValue = Convert.ToInt32(s[i + 1]); slChart.Data.Add(cp); i += 1; } slChart.Colors = color; wcCharts.Add(slChart); wcEng.HasChartLegend = false; wcEng.Legend.Position = LegendPosition.Right; wcEng.Legend.Width = 80; MemoryStream memStream = new MemoryStream(); Bitmap bmp = wcEng.GetBitmap(); Graphics g = Graphics.FromImage(bmp); Pen mypen = new Pen(Color.Black, 1F); g.DrawRectangle(mypen, 0, 0, bmp.Width - 1, bmp.Height - 1); bmp.Save(memStream, ImageFormat.Png); memStream.WriteTo(Response.OutputStream); Response.ContentType = "image/png"; Response.End(); }
private void UpdateOppoUI(string id) { try { ISDataService service; service = SDataDataService.mydataService(); SDataResourceCollectionRequest oppoContactsCollection = new SDataResourceCollectionRequest(service); oppoContactsCollection.ResourceKind = "opportunitycontacts"; oppoContactsCollection.QueryValues.Add("where", "Contact.Id eq '" + id + "'"); AtomFeed oppoContactsFeed = oppoContactsCollection.Read(); picBoxOpportunity.Visible = false; if (oppoContactsFeed.Entries.Count() > 0) { DataTable table = new DataTable(); table.Columns.Add("Id"); table.Columns.Add("Description"); table.Columns.Add("Probability"); table.Columns.Add("Potential"); table.Columns.Add("ActualAmount"); table.Columns.Add("Status"); //-------------------------------------- // Create The Chart ChartEngine engine = new ChartEngine(); engine.Size = picBoxOpportunity.Size; ChartCollection charts = new ChartCollection(engine); engine.Charts = charts; int pointCount = 0; ChartPointCollection data = new ChartPointCollection(); Chart columnChart = new ColumnChart(data, Color.DarkGreen); columnChart.Fill.Color = Color.FromArgb(50, Color.Green); columnChart.ShowLineMarkers = true; columnChart.DataLabels.Visible = true; foreach (AtomEntry entry in oppoContactsFeed.Entries) { SDataPayload oppoContact = entry.GetSDataPayload(); SDataPayload tempOppo = (SDataPayload)oppoContact.Values["Opportunity"]; SDataSingleResourceRequest oppo = new SDataSingleResourceRequest(service); oppo.ResourceKind = "Opportunities"; oppo.ResourceSelector = "('" + tempOppo.Key + "')"; AtomEntry oppoEnty = oppo.Read(); SDataPayload opportunitiy = (SDataPayload)oppoEnty.GetSDataPayload(); DataRow dr = table.NewRow(); dr[0] = opportunitiy.Key.ToString(); dr[1] = (opportunitiy.Values["Description"] != null ? opportunitiy.Values["Description"].ToString() : "No Description"); dr[2] = (opportunitiy.Values["CloseProbability"] != null ? opportunitiy.Values["CloseProbability"].ToString() + "%" : "0%"); dr[3] = (opportunitiy.Values["SalesPotential"] != null ? String.Format("{0:C}", Convert.ToDecimal(opportunitiy.Values["SalesPotential"])) : ""); dr[4] = (opportunitiy.Values["ActualAmount"] != null ? String.Format("{0:C}", Convert.ToDecimal(opportunitiy.Values["ActualAmount"])) : ""); dr[5] = (opportunitiy.Values["Status"] != null ? opportunitiy.Values["Status"].ToString() : "No Status"); pointCount = Convert.ToInt32(opportunitiy.Values["SalesPotential"].ToString().Substring(0,opportunitiy.Values["SalesPotential"].ToString().IndexOf('.'))); data.Add(new ChartPoint("Some Data", pointCount)); table.Rows.Add(dr); } dgvOpportunities.DataSource = table; dgvOpportunities.Columns["Id"].Visible = false; dgvOpportunities.Refresh(); charts.Add(columnChart); engine.GridLines = GridLines.Horizontal; Image image = engine.GetBitmap(); //-------------------------------------- // At this point we have the chart already //-------------------------------------- // show the already generated image picBoxOpportunity.Image = image; if (SLX_Outlook_AddIn.Properties.Settings.Default.OppoChartPanelMinimized == true) { picBoxOpportunity.Visible = false; } else { picBoxOpportunity.Visible = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Page_Load(object sender, System.EventArgs e) { _questionId = Information.IsNumeric(Request["QuestionId"]) ? int.Parse(Request["QuestionId"]) : -1; _filterId = Information.IsNumeric(Request["FilterId"]) ? int.Parse(Request["FilterId"]) : -1; _sortOrder = Request["SortOrder"] == null ? "ans" : Request["SortOrder"]; if (_questionId == -1) { Response.End(); } else if (!NSurveyUser.Identity.IsAdmin && !NSurveyUser.Identity.HasAllSurveyAccess) { if (!new Question().CheckQuestionUser(_questionId, NSurveyUser.Identity.UserId)) { Response.End(); } } ChartEngine engine = new ChartEngine(); ChartCollection charts = new ChartCollection(engine); engine.Size = new Size(700, 500); engine.Charts = charts; WebChart.ColumnChart chart = new WebChart.ColumnChart(); chart.Fill.Color = Color.FromArgb(98,94,238); chart.MaxColumnWidth = 80; chart.DataLabels.Visible = true; chart.DataLabels.Position = DataLabelPosition.Bottom; chart.DataLabels.ForeColor = Color.White; chart.Shadow.Visible = true; chart.DataLabels.NumberFormat ="0.00"; chart.ShowLineMarkers = true; SetQuestionData(engine, chart); SetMoreProperties(engine); charts.Add(chart); // send chart to browser Bitmap bmp; System.IO.MemoryStream memStream = new System.IO.MemoryStream(); bmp = engine.GetBitmap(); bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); memStream.WriteTo(Response.OutputStream); Response.End(); }
public override PicturePage.Picture GetPictureWithBitmap(int id) { ChartEngine engine = new ChartEngine(); engine.Size = new Size(570, 300); engine.GridLines = WebChart.GridLines.None; engine.ShowXValues = true; engine.ShowYValues = true; engine.LeftChartPadding = 50; engine.BottomChartPadding = 50; engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center; engine.XAxisFont.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical; engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black; ChartCollection charts = new ChartCollection(engine); engine.Charts = charts; List<TransitCounter> counters = SessionManager.GetCachedCollection<TransitCounter>( "GetStatsSummary", SessionManager.Ticket, new TransitStatsQueryOptions(RequestType)); string format; switch (RequestType) { case TransitStats.Type.Daily: format = "MMM d"; break; case TransitStats.Type.Hourly: format = "htt"; break; case TransitStats.Type.Monthly: format = "MMM"; break; case TransitStats.Type.Weekly: format = "MMM dd"; break; case TransitStats.Type.Yearly: format = "yyyy"; break; default: throw new ArgumentOutOfRangeException("type"); } Color fill = Color.Black; ColumnChart chart = new ColumnChart(); chart.ShowLineMarkers = false; chart.ShowLegend = true; chart.Line.Color = Color.White; chart.Line.Width = 2; chart.Fill.Color = engine.Border.Color = fill; chart.Fill.LinearGradientMode = LinearGradientMode.Vertical; chart.MaxColumnWidth = 100; foreach (TransitCounter counter in counters) { chart.Data.Add(new ChartPoint(counter.Created.ToString(format), counter.Count)); } charts.Add(chart); PicturePage.Picture picture = new PicturePage.Picture(); picture.Id = 0; picture.Modified = DateTime.UtcNow; picture.Name = RequestType.ToString(); MemoryStream ds = new MemoryStream(); engine.GetBitmap().Save(ds, ImageFormat.Png); picture.Bitmap = new byte[ds.Length]; MemoryStream ms = new MemoryStream(picture.Bitmap); ds.WriteTo(ms); return picture; }