Inserting a chart using free Spire.xls

Source: Internet
Author: User

Use Free spire.xls Insert Chart

Objective

recently in the study Office Middleware, search the Internet, the more famous there are two:aspose and Spire, both full-featured, Office support is approaching perfect, but the price is not cheap. Searching carefully, we found that the Spire series also has a free version of the product, relative to the commercial version, in the performance and file conversion function has shrunk. After a period of use, I found the free version to meet most of my needs. So write down this article, and share my experience with you, here I use the free Spire.xls, according to the data in the text to insert the chart and save.

Get ready

first from CodePlex(https://freenetexcel.codeplex.com/) downloads the free spire.xls andthen references Spire.License.dll and the Spire.XLS.dll to the project, as shown in:

                                    

Steps

1. Load an existing Excel document that already contains the data needed to generate the chart.


Workbook WB =NewWorkbook ();
Wb. LoadFromFile ("test.xlsx", excelversion.version2010);
Worksheet WS = WB. worksheets[0];

2. Creates a bar chart and sets the data region and position of the chart.

//Create a coulumn clustered chart
Chart chart = ws. Charts.add (excelcharttype.columnclustered);
//Set Region of chart data
Chart. DataRange = ws. range["a1:c5"];
Chart. Seriesdatafromrange =false;
//Set position of chart
Chart. Leftcolumn =1;
Chart. Toprow =7;
Chart. Rightcolumn = One;
Chart. Bottomrow = -;

3. set the chart title format and the format of the two axes.


//Chart title
Chart. ChartTitle ="Sales Market by country";
Chart. Charttitlearea.isbold =true;
Chart. Charttitlearea.size = A;
//Chart Primary Category axis
Chart. Primarycategoryaxis.title ="Country";
Chart. PrimaryCategoryAxis.Font.IsBold =true;
Chart. PrimaryCategoryAxis.TitleArea.IsBold =true;
//Chart Primary Value axis
Chart. Primaryvalueaxis.title ="Sales (in Dollars)";
Chart. Primaryvalueaxis.hasmajorgridlines =false;
Chart. Primaryvalueaxis.minvalue = +;
Chart. PrimaryValueAxis.TitleArea.IsBold =true;
Chart. PrimaryValueAxis.TitleArea.TextRotationAngle =- -;

4. display the data label and set the position to "center".

//Format Data Labels
foreach(Chartserie CSinchChart. Series)
{
Cs. Format.Options.IsVaryColor =true;
Cs. DataPoints.DefaultDataPoint.DataLabels.HasValue =true;
Cs. DataPoints.DefaultDataPoint.DataLabels.Position = Datalabelpositiontype.center;
}

5. set the legend location to "bottom" and save the file to disk.


Chart. Legend.position = Legendpositiontype.bottom;
Wb. SaveToFile ("sample.xlsx", excelversion.version2010);

generated by the Excel document looks like this:

Summarize

There is no shortage of third-party operations for Excel components, free Spire.xls's advantages lie in its ease of use and full functionality, but it can handle up to 5 workbooks , up to a maximum of Data, these are the limitations of the free version. But it's enough for me.

Inserting a chart using free Spire.xls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.