EasyXLS™ library allows you to create Excel charts that can be positioned inside a worksheet. A chart can have two positions, as a distinct sheet or as an object in a worksheet. This chapter explains the second situation.
The Excel chart that is an object inside a worksheet has the position relative to sheet cells and the width and height of the Excel chart is specified in pixels.
EasyXLS also allows you to read Excel files that contain charts and extract chart information.
' Create Excel chart positioned at A10 cell with 600px width, 300px heightDim xlsChart As ExcelChart = New ExcelChart("A10", 600, 300)
' Set chart data source
xlsChart.easy_addSeries("=SourceData!$B$1", "=SourceData!$B$2:$B$5")
xlsChart.easy_addSeries("=SourceData!$C$1", "=SourceData!$C$2:$C$5")
xlsChart.easy_addSeries("=SourceData!$D$1", "=SourceData!$D$2:$D$5")
xlsChart.easy_setCategoryXAxisLabels("=SourceData!$A$2:$A$5")
' Add chart to the worksheetDim xlsWorksheet As ExcelWorksheet = workbook.easy_getSheet("SourceData")
xlsWorksheet.easy_addChart(xlsChart)
.NET:// Create Excel chart positioned at A10 cell with 600px width, 300px height
$xlsChart = new COM("EasyXLS.Charts.ExcelChart");
$xlsChart->setLeftUpperCorner_2("A10");
$xlsChart->setSize(600, 300);
// Set chart data source
$xlsChart->easy_addSeries_2("=SourceData!\$B$1", "=SourceData!\$B$2:\$B$5");
$xlsChart->easy_addSeries_2("=SourceData!\$C$1", "=SourceData!\$C$2:\$C$5");
$xlsChart->easy_addSeries_2("=SourceData!\$D$1", "=SourceData!\$D$2:\$D$5");
$xlsChart->easy_setCategoryXAxisLabels("=SourceData!\$A$2:\$A$5");
// Add chart to the worksheet
$xlsWorksheet = $workbook->easy_getSheet("SourceData");
$xlsWorksheet->easy_addChart($xlsChart);
Click here to see Continuous Code ListingJava:// Create Excel chart positioned at A10 cell with 600px width, 300px height
$xlsChart = new java("EasyXLS.Charts.ExcelChart");
$xlsChart->setLeftUpperCorner("A10");
$xlsChart->setSize(600, 300);
// Set chart data source
$xlsChart->easy_addSeries("=SourceData!\$B$1", "=SourceData!\$B$2:\$B$5");
$xlsChart->easy_addSeries("=SourceData!\$C$1", "=SourceData!\$C$2:\$C$5");
$xlsChart->easy_addSeries("=SourceData!\$D$1", "=SourceData!\$D$2:\$D$5");
$xlsChart->easy_setCategoryXAxisLabels("=SourceData!\$A$2:\$A$5");
// Add the chart to the first worksheet
$xlsWorksheet = $workbook->easy_getSheet("SourceData");
$xlsWorksheet->easy_addChart($xlsChart);
Click here to see Continuous Code Listing
' Create Excel chart positioned at A10 cell with 600px width, 300px heightset xlsChart = Server.CreateObject("EasyXLS.Charts.ExcelChart")
xlsChart.setLeftUpperCorner_2("A10")
xlsChart.setSize 600, 300
' Set chart data source
xlsChart.easy_addSeries_2 "=SourceData!$B$1", "=SourceData!$B$2:$B$5"
xlsChart.easy_addSeries_2 "=SourceData!$C$1", "=SourceData!$C$2:$C$5"
xlsChart.easy_addSeries_2 "=SourceData!$D$1", "=SourceData!$D$2:$D$5"
xlsChart.easy_setCategoryXAxisLabels("=SourceData!$A$2:$A$5")
' Add chart to the worksheetset xlsWorksheet = workbook.easy_getSheet("SourceData")
xlsWorksheet.easy_addChart(xlsChart)
.NET:# Create Excel chart positioned at A10 cell with 600px width, 300px height
xlsChart = ExcelChart("A10", 600, 300)
# Set chart data source
xlsChart.easy_addSeries("=SourceData!$B$1", "=SourceData!$B$2:$B$5")
xlsChart.easy_addSeries("=SourceData!$C$1", "=SourceData!$C$2:$C$5")
xlsChart.easy_addSeries("=SourceData!$D$1", "=SourceData!$D$2:$D$5")
xlsChart.easy_setCategoryXAxisLabels("=SourceData!$A$2:$A$5")
# Add chart to the worksheet
workbook.easy_getSheet("SourceData").easy_addChart(xlsChart)
Click here to see Continuous Code ListingJava:# Create Excel chart positioned at A10 cell with 600px width, 300px height
xlsChart = gateway.jvm.ExcelChart("A10", 600, 300)
# Set chart data source
xlsChart.easy_addSeries("=SourceData!$B$1", "=SourceData!$B$2:$B$5")
xlsChart.easy_addSeries("=SourceData!$C$1", "=SourceData!$C$2:$C$5")
xlsChart.easy_addSeries("=SourceData!$D$1", "=SourceData!$D$2:$D$5")
xlsChart.easy_setCategoryXAxisLabels("=SourceData!$A$2:$A$5")
# Add chart to the worksheet
workbook.easy_getSheet("SourceData").easy_addChart(xlsChart)
Click here to see Continuous Code Listing
The screen shot provides an example of an exported column chart placed inside a worksheet.
Chart type
EasyXLS™ library provides a large number of chart types, such as column chart, line chart, bar chart, pie chart, scatter chart, area chart, doughnut chart, radar chart, surface chart, bubble chart, stock chart, cylinder chart, cone chart and pyramid chart.
EasyXLS lets you format the chart elements such as chart area, plot area, series, category X axis, value Y axis, gridlines, data table, legend, titles and 3D rotation.