It’s actually not too difficult, but little tricky. Below you can find brief description how you can do it.
to your page. The following code will appear in your YourForm.aspx file:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Drawing; using System.IO; using System.Reflection; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml; using Manco.Chart; using Manco.Chart.Data; using Manco.Chart.Layouts; public partial class Pages_Demo_ShowChart : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // Get char width and height from the query string string sWidth = Request.QueryString["width"]; string sHeight = Request.QueryString["height"]; Size imageSize = new Size(200, 200); try { imageSize.Width = int.Parse(sWidth); } catch (Exception) { } try { imageSize.Height = int.Parse(sHeight); } catch (Exception) { } // Create instance of the Chart Control ChartControl.LicenseFilePath = this.Server.MapPath("~/License"); ChartControl control = new ChartControl(); m_ChartControl.BackColor = Color.White; m_ChartControl.HttpServer = this.Server; m_ChartControl.Size = imageSize; int liCategoryCount = 3; // Set desirable number of the categories int liSeriesCount = 3; // Set desirable number of the series
// Declare array of doubles double[,] ldaData = new double[liCategoryCount, liSeriesCount];
double ldMin = 5; double ldMax = 30;
// Fill array with data here Random rnd = new Random(); for( int i = 0; i < liCategoryCount; i++) { for( int j = 0; j < liSeriesCount; j++) { ldaData[i,j] = ldMin + (ldMax - ldMin) * rnd.NextDouble(); } }
// Create IChartDataSource object IChartDataSource loDataSource = new ArrayDataSource(ldaData, DataOrientation.CategoryInRow);
// Load data to the chart m_ChartControl.Charts[0].LoadData(loDataSource, false, true); // Load chart theme // Check if we have Chart Theme stored in the session XmlDocument xmlThemeDocument; xmlThemeDocument = (XmlDocument)Session["Theme"]; if (xmlThemeDocument == null) { xmlThemeDocument = new XmlDocument(); ResourceLoader.WebServer = this.Server; Stream stream = ResourceLoader.GetFileStream(this.Server.MapPath("~/DemoChart.xml")); xmlThemeDocument.Load(stream); stream.Close(); } m_ChartControl.LoadTheme(xmlThemeDocument.DocumentElement); // Drow chart m_ChartControl.Init3DRenderer(); m_ChartControl.Draw(); // make a memory stream to work with the image bytes MemoryStream imageStream = new MemoryStream(); // put the chart image into the memory stream m_ChartControl.Image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png); // make byte array the same size as the image byte[] imageContent = new Byte[imageStream.Length]; // rewind the memory stream imageStream.Position = 0; // load the byte array with the image imageStream.Read(imageContent, 0, (int)imageStream.Length); imageStream.Close(); // return byte array to caller with image type Response.ContentType = "image/png"; Response.BinaryWrite(imageContent); // Don't forget to dispose chart control after use. m_ChartControl.Dispose(); } }