Thursday, January 28, 2010

Pie chart in DotnetCharting

protected void Pie_Billing_Charges()


{

// Set the title.

Chart_PieBillChrgs.Title = "Voice Services Charges by Service Type ";

Chart_PieBillChrgs.Size = "550x320";

Chart_PieBillChrgs.LegendBox.Position = LegendBoxPosition.None;

Chart_PieBillChrgs.LegendBox.CornerTopRight = dotnetCHARTING.BoxCorner.Round;

Chart_PieBillChrgs.DefaultElement.ShowValue = true;

Chart_PieBillChrgs.TitleBox.Position = TitleBoxPosition.Full;

// Set 3D

Chart_PieBillChrgs.Use3D = true;

Chart_PieBillChrgs.DefaultChartArea.ClearColors();

Chart_PieBillChrgs.DefaultElement.SmartLabel.Text = "%name: %Value";

//Chart_PieBillChrgs.LegendBox.Template = "%icon %name";

// Set the chart Type

Chart_PieBillChrgs.Type = ChartType.Pie;



// Set default transparency

Chart_PieBillChrgs.DefaultSeries.DefaultElement.Transparency = 15;

Chart_PieBillChrgs.ShadingEffectMode = ShadingEffectMode.Five;

Chart_PieBillChrgs.YAxis.FormatString = "Currency";



// Set show value

Chart_PieBillChrgs.DefaultSeries.DefaultElement.ShowValue = true;



// Set labeling mode.

Chart_PieBillChrgs.PieLabelMode = PieLabelMode.Outside;





// Set the directory where the images will be stored.

Chart_PieBillChrgs.TempDirectory = "temp";



SqlConnection conn = CreateConnection();

if (conn!= null)

conn.Open();

try

{

DataTable dt = new DataTable();

SqlDataAdapter sda = new SqlDataAdapter();

sda.SelectCommand = new SqlCommand("select id,colvalue,colname from Billing where id = (select max(id) from Billing) order by colname", conn);

sda.Fill(dt);

Chart_PieBillChrgs.Series.Data = dt;

Chart_PieBillChrgs.SeriesCollection.Add();

Chart_PieBillChrgs.SeriesCollection[0].DefaultElement.Color = Color.FromArgb(49, 255, 49);

Chart_PieBillChrgs.SeriesCollection[1].DefaultElement.Color = Color.FromArgb(255, 255, 0);

Chart_PieBillChrgs.SeriesCollection[2].DefaultElement.Color = Color.FromArgb(255, 99, 49);

Chart_PieBillChrgs.SeriesCollection[3].DefaultElement.Color = Color.FromArgb(0, 156, 255);



}

catch (Exception ex)

{



}

finally

{

conn.Close();

}

}



<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>




<dotnet:Chart id="Chart_PieBillChrgs" runat="server"/>

1 comments:

Metalda said...

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Lucy

http://forextradin-g.net