Example: Pie Chart
A simple Pie chart is constructed in this example. Pie slice labels and colors are set and one pie slice is exploded from the center. This class extends JFrameChart
, which manages the window.
using Imsl.Chart2D;
using Imsl.Stat;
using System;
using System.Windows.Forms;
public class PieEx1 : FrameChart
{
public PieEx1()
{
Chart chart = this.Chart;
AxisXY axis = new AxisXY(chart);
// Create an instance of a Pie Chart
double[] y = new double[]{10.0, 20.0, 30.0, 40.0};
Pie pie = new Pie(chart, y);
// Set the Pie Chart Title
chart.ChartTitle.SetTitle("A Simple Pie Chart");
// Set the colors of the Pie Slices
PieSlice[] slice = pie.GetPieSlice();
slice[0].FillColor = System.Drawing.Color.Red;
slice[1].FillColor = System.Drawing.Color.Blue;
slice[2].FillColor = System.Drawing.Color.Black;
slice[3].FillColor = System.Drawing.Color.Yellow;
// Set the Pie Slice Labels
pie.LabelType = Imsl.Chart2D.Pie.LABEL_TYPE_TITLE;
slice[0].SetTitle("Fish");
slice[1].SetTitle("Pork");
slice[2].SetTitle("Poultry");
slice[3].SetTitle("Beef");
// Explode a Pie Slice
slice[0].Explode = 0.2;
}
public static void Main(string[] argv)
{
System.Windows.Forms.Application.Run(new PieEx1());
}
}
Output
Link to C# source.