Reply to topic  [ 7 posts ] 
Pie charts 
Author Message
Reply with quote
Post Pie charts
How can I generate advanced pie charts in a web project?

Wed Jun 14, 2006 3:29 am

Joined: Fri Feb 03, 2006 12:23 pm
Posts: 3
Reply with quote
Post Pie chart
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EasyXLS;
using EasyXLS.Constants;
namespace TestWebEasyXLS
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
/*--------License Information --------*/
public static string sLicense = "License";
public static string sLicenseKey = "LicenseKey";

private void Page_Load(object sender, System.EventArgs e)
Response.Write("Tutorial 17 adapted<br>-----------<br>");
//Create an instance of the object that generates Excel files
ExcelDocument xls = new ExcelDocument();

//Add one worksheet
// ----------------------------------------------------------------------
//Insert values
ExcelTable xlsTable1 = ((ExcelWorksheet)xls.easy_getSheet("SourceData")).easy_getExcelTable();
xlsTable1.easy_getCell(0, 0).setValue("Show Date");
xlsTable1.easy_getCell(0, 1).setValue("Available Places");
xlsTable1.easy_getCell(0, 2).setValue("Available -");
xlsTable1.easy_getCell(0, 3).setValue("Sold -");
xlsTable1.easy_getCell(1, 0).setValue("03/13/2005 00:00:00");
xlsTable1.easy_getCell(1, 0).setFormat(EasyXLS.Constants.Format.FORMAT_DATE);
xlsTable1.easy_getCell(2, 0).setValue("03/14/2005 00:00:00");
xlsTable1.easy_getCell(2, 0).setFormat(EasyXLS.Constants.Format.FORMAT_DATE);
xlsTable1.easy_getCell(3, 0).setValue("03/15/2005 00:00:00");
xlsTable1.easy_getCell(3, 0).setFormat(EasyXLS.Constants.Format.FORMAT_DATE);
xlsTable1.easy_getCell(4, 0).setValue("03/16/2005 00:00:00");
xlsTable1.easy_getCell(4, 0).setFormat(EasyXLS.Constants.Format.FORMAT_DATE);
xlsTable1.easy_getCell(1, 1).setValue("10000");
xlsTable1.easy_getCell(2, 1).setValue("5000");
xlsTable1.easy_getCell(3, 1).setValue("8500");
xlsTable1.easy_getCell(4, 1).setValue("1000");
xlsTable1.easy_getCell(1, 2).setValue("8000");
xlsTable1.easy_getCell(2, 2).setValue("4000");
xlsTable1.easy_getCell(3, 2).setValue("6000");
xlsTable1.easy_getCell(4, 2).setValue("1000");
xlsTable1.easy_getCell(1, 3).setValue("920");
xlsTable1.easy_getCell(2, 3).setValue("1005");
xlsTable1.easy_getCell(3, 3).setValue("342");
xlsTable1.easy_getCell(4, 3).setValue("967");
//Add the chart
xls.easy_addChart("Chart", "=SourceData!$A$1:$B$5", Chart.SERIES_IN_COLUMNS);
ExcelChartSheet xlsChart = (ExcelChartSheet)xls.easy_getSheetAt(1);

//Generate the file
Response.Write("Writing file Tutorial17.xls.");
xls.easy_WriteExcelFile("C:\\Inetpub\\wwwroot\\Tutorial17.xls", sLicense, sLicenseKey);
/*//Or write directly in Response and you don't need any permissions
//Start to prepare the Response
Response.AppendHeader("content-disposition", "attachment; filename=Tutorial17.xls");
Response.ContentType = "application/octetstream";
//Generate the file and prompt the "Open or Save Dialog Box"
xls.easy_WriteExcelFile(Response.OutputStream, sLicense, sLicenseKey);*/

//Confirm generation
String sError = xls.easy_getError();
if (sError.Equals(""))
Response.Write("<br>File successfully created.");
Response.Write("<br>Error encountered: " + sError);

//Dispose memory
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
// CODEGEN: This call is required by the ASP.NET Web Form Designer.

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
this.Load += new System.EventHandler(this.Page_Load);

Thu Jun 15, 2006 8:21 am
Reply with quote
Post Pie options
Yes, but is it possible to change de colors of each pieces by code? And how can you indicate de type of legends?
Making a pie chart from Excel, colors are assignated automatically, but from EasyXLS I always get then blue. And I don't know how to tell chart to show legends in percentage or how to access to the options of each category (I can get refereces to series, but in a pie chart usually you only have a single serie). It is easy from Excel, but is it possible by code?
I think rows and columns charts are quite more versatile with EasyXLS.
(My version of control is 5.1)
Greetings (and sorrry for my english; I'm spanish)

Mon Nov 20, 2006 8:28 am

Joined: Mon Nov 20, 2006 9:59 am
Posts: 1
Reply with quote
Please download and install the new trial version EasyXLS 5.3. In this version the chart pie is generated in different colors. This colors cannot be changed from the code. Here is some code that and I hope it can help you.

//Here you create the document with an worksheet named DATA
         ExcelDocument xls_doc = new ExcelDocument();
         ExcelTable xls_tabel = ((ExcelWorksheet)xls_doc.easy_getSheet("DATA")).easy_getExcelTable();
         xls_tabel.easy_getCell(0,1).setValue("Data to Write");
         ExcelChartSheet xlsChartSheet = new ExcelChartSheet("CHART");
         ExcelChart xlsChart = new ExcelChart();   
         //Here you populate the worksheet whith some data
         for (int i = 1 ; i < 10; i++)
            xls_tabel.easy_getCell(i,0).setValue("DATA " + i + "");

         //This function create a PIE type chartsheet
         ExcelChartLegend xlsLegend = new ExcelChartLegend();

Mon Nov 20, 2006 10:50 am
Reply with quote
I will try. About changing categories colours, I have seen Excel does not allow it neither and apply them automatically...

Mon Nov 20, 2006 11:12 am

Joined: Tue May 13, 2008 3:32 am
Posts: 2
Reply with quote
Post pie charts
What can I do if I want to create a piechart whith several cells not with a cell range? i.e. with A1;G4;F32;H15
Thank you!

Fri May 16, 2008 6:12 am

Joined: Wed Nov 07, 2007 4:42 am
Posts: 62
Reply with quote
Post Pie Chart
Here is the code that you need:


ExcelDocument xls = new ExcelDocument();
//Add one worksheet

// ----------------------------------------------------------------------

//Insert values]

ExcelTable xlsTable1 = ((ExcelWorksheet)xls.easy_getSheet("SourceData")).easy_getExcelTable();

xlsTable1.easy_getCell(0, 0).setValue("23");
xlsTable1.easy_getCell(3, 6).setValue("15");
xlsTable1.easy_getCell(31, 5).setValue("10");
xlsTable1.easy_getCell(14, 7).setValue("42");

//Add the chart

//Get the previously added chart
ExcelChart xlsChart = ((ExcelChartSheet)xls.easy_getSheetAt(1)).easy_getExcelChart();

//Modifying chart type


//Generate the file
xls.easy_WriteXLSFile("D:\\Customer support\\Customers\\forum_final.xls");

//Confirm generation
String sError = xls.easy_getError();
if (sError.Equals(""))
   Console.Write("\nFile successfully created. Press Enter to Exit...");
   Console.Write("\nError encountered: " + sError + "\nPress Enter to Exit...");
//Dispose memory

Thu May 22, 2008 5:49 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.