static void Main(string[] args) { // Instantiating a Workbook object Workbook workbook = new Workbook(); // Obtaining the reference of the first worksheet WorksheetCollection worksheets = workbook.Worksheets; Worksheet sheet = worksheets[0]; // Adding some sample value to cells Cells cells = sheet.Cells; Cell cell = cells["A1"]; cell.Value = 50; cell = cells["A2"]; cell.Value = 100; cell = cells["A3"]; cell.Value = 150; cell = cells["B1"]; cell.Value = 4; cell = cells["B2"]; cell.Value = 20; cell = cells["B3"]; cell.Value = 50; ChartCollection charts = sheet.Charts; // Adding a chart to the worksheet int chartIndex = charts.Add(ChartType.Pyramid, 5, 0, 15, 5); Chart chart = charts[chartIndex]; //Save the chart image file. chart.ToImage("AsposeChartImage.png", ImageFormat.Png); }
public void Initialize() { _chartDescriptorWithData = Mock.Create<ChartPanel>(Constructor.Mocked, Behavior.Loose); var chartCollection = new ChartCollection(); _chartDescriptorWithData.Charts = chartCollection; var xChart = Mock.Create<XBarChart>(Constructor.Mocked, Behavior.Loose); Mock.Arrange(() => xChart.IsChild).Returns(true); xChart.DataSource = new MobileObservableCollection<SampleUnit> { CreateSample(1.0, 1.61, 1.36, 1.11, 7), CreateSample(1.0, 1.61, 1.36, 1.11, 7), CreateSample(0.8571428571428571, 1.61, 1.36, 1.11, 7), CreateSample(0.0, 1.61, 1.36, 1.11, 7), CreateSample(0.0, 1.61, 1.36, 1.11, 7), CreateSample(0.0, 1.61, 1.36, 1.11, 7), CreateSample(0.5714285714285714, 1.61, 1.36, 1.11, 7), CreateSample(2.0, 1.61, 1.36, 1.11, 7), CreateSample(3.4285714285714284, 1.61, 1.36, 1.11, 7), CreateSample(4.7142857142857144, 1.61, 1.36, 1.11, 7) }; chartCollection.Add(xChart); var rChart = Mock.Create<RChart>(Constructor.Mocked, Behavior.Loose); Mock.Arrange(() => rChart.IsChild).Returns(true); rChart.DataSource = new MobileObservableCollection<SampleUnit> { CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(1.0, 1.15, 0.6, 0.05, 7), CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(0.0, 1.15, 0.6, 0.05, 7), CreateSample(1.0, 1.15, 0.6, 0.05, 7), CreateSample(2.0, 1.15, 0.6, 0.05, 7), CreateSample(1.0, 1.15, 0.6, 0.05, 7), CreateSample(1.0, 1.15, 0.6, 0.05, 7) }; chartCollection.Add(rChart); }
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(); }
static void Main(string[] args) { // Instantiating a Workbook object Workbook workbook = new Workbook(); // Obtaining the reference of the first worksheet WorksheetCollection worksheets = workbook.Worksheets; Worksheet sheet = worksheets[0]; // Adding some sample value to cells Cells cells = sheet.Cells; Cell cell = cells["A1"]; cell.Value = 50; cell = cells["A2"]; cell.Value = 100; cell = cells["A3"]; cell.Value = 150; cell = cells["B1"]; cell.Value = 4; cell = cells["B2"]; cell.Value = 20; cell = cells["B3"]; cell.Value = 50; ChartCollection charts = sheet.Charts; // Adding a chart to the worksheet int chartIndex = charts.Add(ChartType.Pyramid, 5, 0, 15, 5); Chart chart = charts[chartIndex]; // Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3" SeriesCollection serieses = chart.NSeries; serieses.Add("A1:B3", true); // Saving the Excel file workbook.Save("Chart_Aspose.xls"); }
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; }
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(); }
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(); }
public static void Main(string[] args) { //ExStart:1 // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } //Instantiate a new Workbook Workbook book = new Workbook(); //Add a Data Worksheet Worksheet dataSheet = book.Worksheets.Add("DataSheet"); //Add Chart Worksheet Worksheet sheet = book.Worksheets.Add("MyChart"); //Put some values into the cells in the data worksheet dataSheet.Cells["B1"].PutValue(1); dataSheet.Cells["B2"].PutValue(2); dataSheet.Cells["B3"].PutValue(3); dataSheet.Cells["A1"].PutValue("A"); dataSheet.Cells["A2"].PutValue("B"); dataSheet.Cells["A3"].PutValue("C"); //Define the Chart Collection ChartCollection charts = sheet.Charts; //Add a Column chart to the Chart Worksheet int chartSheetIdx = charts.Add(ChartType.Column, 5, 0, 25, 15); //Get the newly added Chart Aspose.Cells.Charts.Chart chart = book.Worksheets[2].Charts[0]; //Set the background/foreground color for PlotArea/ChartArea chart.PlotArea.Area.BackgroundColor = Color.White; chart.ChartArea.Area.BackgroundColor = Color.White; chart.PlotArea.Area.ForegroundColor = Color.White; chart.ChartArea.Area.ForegroundColor = Color.White; //Hide the Legend chart.ShowLegend = false; //Add Data Series for the Chart chart.NSeries.Add("DataSheet!B1:B3", true); //Specify the Category Data chart.NSeries.CategoryData = "DataSheet!A1:A3"; //Get the Data Series Aspose.Cells.Charts.Series ser = chart.NSeries[0]; //Apply the 3-D formatting ShapePropertyCollection spPr = ser.ShapeProperties; Format3D fmt3d = spPr.Format3D; //Specify Bevel with its height/width Bevel bevel = fmt3d.TopBevel; bevel.Type = BevelPresetType.Circle; bevel.Height = 2; bevel.Width = 5; //Specify Surface material type fmt3d.SurfaceMaterialType = PresetMaterialType.WarmMatte; //Specify surface lighting type fmt3d.SurfaceLightingType = LightRigType.ThreePoint; //Specify lighting angle fmt3d.LightingAngle = 20; //Specify Series background/foreground and line color ser.Area.BackgroundColor = Color.Maroon; ser.Area.ForegroundColor = Color.Maroon; ser.Border.Color = Color.Maroon; //Save the Excel file book.Save(dataDir + "3d_format.out.xlsx"); //ExEnd:1 }
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); }
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(); }
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); }
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 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; }
public static void Run() { // Instantiate a new Workbook Workbook book = new Workbook(); //Rename the first worksheet book.Worksheets[0].Name = "DataSheet"; // Add a Data Worksheet Worksheet dataSheet = book.Worksheets["DataSheet"]; // Add Chart Worksheet Worksheet sheet = book.Worksheets.Add("MyChart"); // Put some values into the cells in the data worksheet dataSheet.Cells["B1"].PutValue(1); dataSheet.Cells["B2"].PutValue(2); dataSheet.Cells["B3"].PutValue(3); dataSheet.Cells["A1"].PutValue("A"); dataSheet.Cells["A2"].PutValue("B"); dataSheet.Cells["A3"].PutValue("C"); // Define the Chart Collection ChartCollection charts = sheet.Charts; // Add a Column chart to the Chart Worksheet int chartSheetIdx = charts.Add(ChartType.Column, 5, 0, 25, 15); // Get the newly added Chart Aspose.Cells.Charts.Chart chart = book.Worksheets["MyChart"].Charts[0]; // Set the background/foreground color for PlotArea/ChartArea chart.PlotArea.Area.BackgroundColor = Color.White; chart.ChartArea.Area.BackgroundColor = Color.White; chart.PlotArea.Area.ForegroundColor = Color.White; chart.ChartArea.Area.ForegroundColor = Color.White; // Hide the Legend chart.ShowLegend = false; // Add Data Series for the Chart chart.NSeries.Add("DataSheet!B1:B3", true); // Specify the Category Data chart.NSeries.CategoryData = "DataSheet!A1:A3"; // Get the Data Series Aspose.Cells.Charts.Series ser = chart.NSeries[0]; // Apply the 3-D formatting ShapePropertyCollection spPr = ser.ShapeProperties; Format3D fmt3d = spPr.Format3D; // Specify Bevel with its height/width Bevel bevel = fmt3d.TopBevel; bevel.Type = BevelPresetType.Circle; bevel.Height = 2; bevel.Width = 5; // Specify Surface material type fmt3d.SurfaceMaterialType = PresetMaterialType.WarmMatte; // Specify surface lighting type fmt3d.SurfaceLightingType = LightRigType.ThreePoint; // Specify lighting angle fmt3d.LightingAngle = 20; // Specify Series background/foreground and line color ser.Area.BackgroundColor = Color.Maroon; ser.Area.ForegroundColor = Color.Maroon; ser.Border.Color = Color.Maroon; // Save the Excel file book.Save(outputDir + "outputApplying3DFormat.xlsx"); Console.WriteLine("Applying3DFormat executed successfully."); }
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(); }