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
xls.easy_addWorksheet("SourceData");
// ----------------------------------------------------------------------
//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");
xlsTable1.easy_getColumnAt(0).setWidth(100);
xlsTable1.easy_getColumnAt(1).setWidth(100);
xlsTable1.easy_getColumnAt(2).setWidth(100);
xlsTable1.easy_getColumnAt(3).setWidth(100);
//-------------------------------------
//Add the chart
xls.easy_addChart("Chart", "=SourceData!$A$1:$B$5", Chart.SERIES_IN_COLUMNS);
ExcelChartSheet xlsChart = (ExcelChartSheet)xls.easy_getSheetAt(1);
xlsChart.easy_setChartType(Chart.CHART_TYPE_PIE_3D_EXPLODED);

//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";
Response.Clear();
//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.");
else
Response.Write("<br>Error encountered: " + sError);

//Dispose memory
Response.End();
xls.Dispose();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <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);
}
#endregion
}
}


Thu Jun 15, 2006 8:21 am
Profile
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
Post 
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.

Code:
//Here you create the document with an worksheet named DATA
         ExcelDocument xls_doc = new ExcelDocument();
         xls_doc.easy_addWorksheet("DATA");
         ExcelTable xls_tabel = ((ExcelWorksheet)xls_doc.easy_getSheet("DATA")).easy_getExcelTable();
         
         xls_tabel.easy_getCell(0,0).setValue("Data");
         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 + "");
            xls_tabel.easy_getCell(i,1).setValue("=10*"+i);
            
         }

               
         //This function create a PIE type chartsheet
         xlsChart.easy_setChartType(Chart.CHART_TYPE_PIE);
         
         xlsChart.easy_addSeries("DATA","=DATA!$B2:B10");
         xlsChart.easy_setCategoryXAxisLabels("=DATA!$A$2:$A10");
         xlsChart.easy_getSeriesAt(0).setDataLabels(Chart.SERIES_DATA_LABELS_SHOW_PERCENT);
         
         xlsChartSheet.easy_setExcelChart(xlsChart);
         xls_doc.easy_addChart(xlsChartSheet);
         
         ExcelChartLegend xlsLegend = new ExcelChartLegend();
         xlsChart.easy_setLegend(xlsLegend);
         
         
         xls_doc.easy_WriteExcelFile("C:\\Inetpub\\wwwroot\\Data.xls");


Mon Nov 20, 2006 10:50 am
Profile
Reply with quote
Post 
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
Profile

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

Code:

ExcelDocument xls = new ExcelDocument();
      
//Add one worksheet
xls.easy_addWorksheet("SourceData");


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

//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
xls.easy_addChart("Chart");

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

//Modifying chart type
xlsChart.easy_setChartType(Chart.CHART_TYPE_PIE);

xlsChart.easy_addSeries("series","=(SourceData!$A$1,SourceData!$G$4,SourceData!$H$15)");

//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...");
else
   Console.Write("\nError encountered: " + sError + "\nPress Enter to Exit...");
      
//Dispose memory
xls.Dispose();
      
Console.ReadLine()



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 0 guests


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.