Import all Drawings name spaces.
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Imaging;
using System.Drawing.Text;
Since to determine the angle of each sector in pie chart we follow following math formula
x°=value of Item A/Total value of all items * 360°
Place a listbox and a button on page. fill listbox with some items
float angletosweep=0;
float totalangle=0;
int _TotalvalueOfAllItems = 0;
for (int index = 0;
index < ListBox1.Items.Count; index++)
{
_TotalvalueOfAllItems += Convert.ToInt32(ListBox1.Items[index].Text.Trim());
}
Bitmap _InMemoryBitmap = new Bitmap(200, 200);
Graphics g = Graphics.FromImage(_InMemoryBitmap);
Pen _pen = new Pen(Color.Indigo);
Rectangle _rectangle = new Rectangle(20, 20, 100,
100);
SolidBrush _brush = new
SolidBrush(Color.Indigo);
for(int
item=0;item<ListBox1.Items.Count;item++)
{
angletosweep = 360 *(Convert.ToInt32(ListBox1.Items[item].Text)) /
(_TotalvalueOfAllItems);
g.FillPie(new SolidBrush(ColorCodes(item)), _rectangle, totalangle,
angletosweep);
//some code omitted.
}
_InMemoryBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
g.Dispose();
_InMemoryBitmap.Dispose();
}
private Color
ColorCodes(int item)
{
Color[] _colorcodes = new Color[] { Color.Green, Color.Yellow ,
Color.LightCoral, Color.Turquoise , Color.Tomato ,
Color.Tan };
return _colorcodes[item];
}
call this page from another page and place the url into img tag of calling page.
Can you an example of a 3D piechart.
ReplyDelete