SlideShare a Scribd company logo
1 of 5
How to Use C# Create Excel bar Chart

Why Create Excel Bar Chart?
For numerical comparisons, bar chart is a classic solution. Bar chart (graph) is a chart with
rectangular bars with lengths proportional to the values that they represent. The bars can be plotted
vertically or horizontally. A bar chart is very useful if you are trying to record certain information
whether it is continuous or not continuous data. In bar charts, a class or group can have a single
category of data, or they can be broken down further into multiple categories for greater depth of
analysis. And in Microsoft Excel, it is the same useful!

How to Use C# Create Excel Bar Chart?
Spire.XLS for .NET allows user to use C# create Excel bar chart. Use C# to create Excel bar chart
could be as easy as in Microsoft Excel. The whole process is almost the same such as write chart
data, set region/position of chart, Write chart title, chart data information, etc. The difference is we
need fill these data in C# application with codes around. Below is a sample for C# code used to
create Excel bar charts. Download Spire.XLS (or Spire.Office) with .NET framework 2.0 (or
above) together and use the code to create Excel Bar Chart right now.

C# Excel Bar Chart:
using Spire.Xls;
using Spire.Xls.Charts;

namespace Spire.Xls.Sample
{
    class program
    {
         static void Main()
         {
               Application.Run(new Form1());
         }

          private void btnRun_Click(object sender, System.EventArgs e)
          {
               Workbook workbook = new Workbook();

               //Initailize worksheet
               workbook.CreateEmptySheets(1);
               Worksheet sheet = workbook.Worksheets[0];
               sheet.Name = "Chart data";
               sheet.GridLinesVisible = false;

              //Writes chart data
              CreateChartData(sheet);
       //Add a new chart worsheet to workbook
Chart chart = sheet.Charts.Add();

       //Set region of chart data
       chart.DataRange = sheet.Range["A1:C5"];
       chart.SeriesDataFromRange = false;

       //Set position of chart
       chart.LeftColumn = 1;
       chart.TopRow = 6;
       chart.RightColumn = 11;
       chart.BottomRow = 29;



       if (checkBox1.Checked)
       {
             chart.ChartType = ExcelChartType.Bar3DClustered;
       }
       else
       {
             chart.ChartType = ExcelChartType.BarClustered;
       }

//Chart title
        chart.ChartTitle = "Sales market by country";
        chart.ChartTitleArea.IsBold = true;
        chart.ChartTitleArea.Size = 12;

       chart.PrimaryCategoryAxis.Title = "Country";
       chart.PrimaryCategoryAxis.Font.IsBold = true;
       chart.PrimaryCategoryAxis.TitleArea.IsBold = true;
       chart.PrimaryCategoryAxis.TitleArea.TextRotationAngle = 90;

        chart.PrimaryValueAxis.Title = "Sales(in Dollars)";
        chart.PrimaryValueAxis.HasMajorGridLines = false;
chart.PrimaryValueAxis.MinValue = 1000;
        chart.PrimaryValueAxis.TitleArea.IsBold = true;



foreach (Charts.ChartSerie cs in chart.Series)
{
   cs.Format.Options.IsVaryColor = true;
   cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
}
chart.Legend.Position = LegendPositionType.Top;
             workbook.SaveToFile("Sample.xls");
             ExcelDocViewer(workbook.FileName);
        }

        private void CreateChartData(Worksheet sheet)
        {
             //Country
             sheet.Range["A1"].Value = "Country";
             sheet.Range["A2"].Value = "Cuba";
             sheet.Range["A3"].Value = "Mexico";
             sheet.Range["A4"].Value = "France";
             sheet.Range["A5"].Value = "German";

             //Jun
             sheet.Range["B1"].Value = "Jun";
             sheet.Range["B2"].NumberValue = 6000;
             sheet.Range["B3"].NumberValue = 8000;
             sheet.Range["B4"].NumberValue = 9000;
             sheet.Range["B5"].NumberValue = 8500;

             //Jun
             sheet.Range["C1"].Value = "Aug";
             sheet.Range["C2"].NumberValue = 3000;
             sheet.Range["C3"].NumberValue = 2000;
             sheet.Range["C4"].NumberValue = 2300;
             sheet.Range["C5"].NumberValue = 4200;

             //Style
             sheet.Range["A1:C1"].Style.Font.IsBold = true;
             sheet.Range["A2:C2"].Style.KnownColor = ExcelColors.LightYellow;
             sheet.Range["A3:C3"].Style.KnownColor = ExcelColors.LightGreen1;
             sheet.Range["A4:C4"].Style.KnownColor = ExcelColors.LightOrange;
             sheet.Range["A5:C5"].Style.KnownColor = ExcelColors.LightTurquoise;

             //Border
             sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeTop].Color          =
Color.FromArgb(0, 0, 128);
             sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeTop].LineStyle      =
LineStyleType.Thin;
             sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeBottom].Color       =
Color.FromArgb(0, 0, 128);
             sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeBottom].LineStyle   =
LineStyleType.Thin;
sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeLeft].Color                    =
Color.FromArgb(0, 0, 128);
             sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeLeft].LineStyle                =
LineStyleType.Thin;
             sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeRight].Color                   =
Color.FromArgb(0, 0, 128);
             sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeRight].LineStyle               =
LineStyleType.Thin;

               sheet.Range["B2:C5"].Style.NumberFormat = ""$"#,##0";
          }

          private void ExcelDocViewer( string fileName )
          {
               try
               {
                    System.Diagnostics.Process.Start(fileName);
               }
               catch{}
          }

          private void btnAbout_Click(object sender, System.EventArgs e)
          {
               Close();
          }
     }
}
After running your application with the code above, you will find an Excel bar Chart is created.
More about Spire.XLS
Download Spire.XLS
Purchase Spire.XLS

More Related Content

What's hot

Pivot table presentation
Pivot table presentationPivot table presentation
Pivot table presentationSha Tibnjn
 
Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813Dave Shannon
 
Excel Secrets for Search Marketers
Excel Secrets for Search MarketersExcel Secrets for Search Marketers
Excel Secrets for Search MarketersChris Haleua
 
Crosstab query techniques
Crosstab query techniquesCrosstab query techniques
Crosstab query techniquesaabaap
 
Lesson 16 Working With Charts
Lesson 16   Working With ChartsLesson 16   Working With Charts
Lesson 16 Working With Chartsguevarra_2000
 
Advance-excel-professional-trainer-in-mumbai
Advance-excel-professional-trainer-in-mumbaiAdvance-excel-professional-trainer-in-mumbai
Advance-excel-professional-trainer-in-mumbaiUnmesh Baile
 
Pivot Table & Chart_Parakramesh Jaroli_Pacific University
Pivot Table & Chart_Parakramesh Jaroli_Pacific UniversityPivot Table & Chart_Parakramesh Jaroli_Pacific University
Pivot Table & Chart_Parakramesh Jaroli_Pacific UniversityParakramesh Jaroli
 
Creating graphs in excel
Creating graphs in excelCreating graphs in excel
Creating graphs in excelclynnc
 
Using excel for randomization 1
Using excel for randomization 1Using excel for randomization 1
Using excel for randomization 1Oscar Pascual
 
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...Cengage Learning
 
Creating a graph in excel
Creating a graph in excelCreating a graph in excel
Creating a graph in excelorthms
 

What's hot (20)

Pivot Tables
Pivot TablesPivot Tables
Pivot Tables
 
Pivot Tables
Pivot TablesPivot Tables
Pivot Tables
 
How To Use Excel
How To Use ExcelHow To Use Excel
How To Use Excel
 
Pivot table presentation
Pivot table presentationPivot table presentation
Pivot table presentation
 
Pivot table
Pivot tablePivot table
Pivot table
 
Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813
 
Charts and pivot tables
Charts and pivot tablesCharts and pivot tables
Charts and pivot tables
 
Graphs
GraphsGraphs
Graphs
 
Vlookup In Excel
Vlookup In ExcelVlookup In Excel
Vlookup In Excel
 
Excel Pivot Tables
Excel Pivot TablesExcel Pivot Tables
Excel Pivot Tables
 
Excel Secrets for Search Marketers
Excel Secrets for Search MarketersExcel Secrets for Search Marketers
Excel Secrets for Search Marketers
 
Crosstab query techniques
Crosstab query techniquesCrosstab query techniques
Crosstab query techniques
 
Lesson 16 Working With Charts
Lesson 16   Working With ChartsLesson 16   Working With Charts
Lesson 16 Working With Charts
 
Advance-excel-professional-trainer-in-mumbai
Advance-excel-professional-trainer-in-mumbaiAdvance-excel-professional-trainer-in-mumbai
Advance-excel-professional-trainer-in-mumbai
 
Pivot Table & Chart_Parakramesh Jaroli_Pacific University
Pivot Table & Chart_Parakramesh Jaroli_Pacific UniversityPivot Table & Chart_Parakramesh Jaroli_Pacific University
Pivot Table & Chart_Parakramesh Jaroli_Pacific University
 
Creating graphs in excel
Creating graphs in excelCreating graphs in excel
Creating graphs in excel
 
excel charts
excel chartsexcel charts
excel charts
 
Using excel for randomization 1
Using excel for randomization 1Using excel for randomization 1
Using excel for randomization 1
 
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
Pivot Tables and Beyond Data Analysis in Excel 2013 - Course Technology Compu...
 
Creating a graph in excel
Creating a graph in excelCreating a graph in excel
Creating a graph in excel
 

Similar to C# excel bar chart

C# excel set excel number style
C# excel   set excel number styleC# excel   set excel number style
C# excel set excel number styleChen Stephen
 
Excel Project 1 – MS Excel Use the project description HER.docx
Excel Project 1 – MS Excel Use the project description HER.docxExcel Project 1 – MS Excel Use the project description HER.docx
Excel Project 1 – MS Excel Use the project description HER.docxSANSKAR20
 
Spreadsheet for Year 8
Spreadsheet for Year 8Spreadsheet for Year 8
Spreadsheet for Year 8qistinahJR
 
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docxExcel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docxelbanglis
 
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docxExcel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docxcravennichole326
 
Module 6 component of excel chart
Module 6 component of excel chartModule 6 component of excel chart
Module 6 component of excel chartDr. Shalini Pandey
 
Rick Watkins Docs
Rick Watkins DocsRick Watkins Docs
Rick Watkins Docsrickwatkins
 
Rick Watkins Docs
Rick Watkins DocsRick Watkins Docs
Rick Watkins Docsrickwatkins
 
MS_Excel_Module4.1 ffor beginners yo .pptx
MS_Excel_Module4.1 ffor beginners yo .pptxMS_Excel_Module4.1 ffor beginners yo .pptx
MS_Excel_Module4.1 ffor beginners yo .pptxshagunjain2k22phdcs0
 
introductiontospreadsheetapplications-200127165949.pptx
introductiontospreadsheetapplications-200127165949.pptxintroductiontospreadsheetapplications-200127165949.pptx
introductiontospreadsheetapplications-200127165949.pptxAbhimanyu Verma
 
Chapter 4 class presentation
Chapter 4 class presentationChapter 4 class presentation
Chapter 4 class presentationcmurphysvhs
 
Chapter 4 class presentation
Chapter 4 class presentationChapter 4 class presentation
Chapter 4 class presentationcmurphysvhs
 
Creating & Editing Charts In Microsoft Excel 2003
Creating & Editing Charts In Microsoft Excel 2003Creating & Editing Charts In Microsoft Excel 2003
Creating & Editing Charts In Microsoft Excel 2003bud_00
 
MS excel and their functions keys and their usage
MS excel and their functions keys and their usageMS excel and their functions keys and their usage
MS excel and their functions keys and their usageshumailbashir82
 
Stanley_Exp22_Excel_Ch03_ML1_Airports.xlsxPassengerTop 6 Unite.docx
Stanley_Exp22_Excel_Ch03_ML1_Airports.xlsxPassengerTop 6 Unite.docxStanley_Exp22_Excel_Ch03_ML1_Airports.xlsxPassengerTop 6 Unite.docx
Stanley_Exp22_Excel_Ch03_ML1_Airports.xlsxPassengerTop 6 Unite.docxmckellarhastings
 
Microsoft Excel Glossary & Keyboard Shortcuts-Function Keys
Microsoft Excel Glossary & Keyboard Shortcuts-Function KeysMicrosoft Excel Glossary & Keyboard Shortcuts-Function Keys
Microsoft Excel Glossary & Keyboard Shortcuts-Function Keyssdturton
 
Excel Project 2 – MS Excel Summer 2018 Use the project.docx
Excel Project 2 – MS Excel Summer 2018 Use the project.docxExcel Project 2 – MS Excel Summer 2018 Use the project.docx
Excel Project 2 – MS Excel Summer 2018 Use the project.docxelbanglis
 
WP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightWP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightMICTT Palma
 
YearQuarterLocationCarClass Revenue NumCars 2017Q1DowntownEconomy.docx
YearQuarterLocationCarClass Revenue   NumCars  2017Q1DowntownEconomy.docxYearQuarterLocationCarClass Revenue   NumCars  2017Q1DowntownEconomy.docx
YearQuarterLocationCarClass Revenue NumCars 2017Q1DowntownEconomy.docxadampcarr67227
 

Similar to C# excel bar chart (20)

C# excel set excel number style
C# excel   set excel number styleC# excel   set excel number style
C# excel set excel number style
 
Excel Project 1 – MS Excel Use the project description HER.docx
Excel Project 1 – MS Excel Use the project description HER.docxExcel Project 1 – MS Excel Use the project description HER.docx
Excel Project 1 – MS Excel Use the project description HER.docx
 
Spreadsheet for Year 8
Spreadsheet for Year 8Spreadsheet for Year 8
Spreadsheet for Year 8
 
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docxExcel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
 
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docxExcel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
Excel Project 1 – MS Excel (Summer 2018) Use the project descripti.docx
 
Module 6 component of excel chart
Module 6 component of excel chartModule 6 component of excel chart
Module 6 component of excel chart
 
Rick Watkins Docs
Rick Watkins DocsRick Watkins Docs
Rick Watkins Docs
 
Rick Watkins Docs
Rick Watkins DocsRick Watkins Docs
Rick Watkins Docs
 
MS_Excel_Module4.1 ffor beginners yo .pptx
MS_Excel_Module4.1 ffor beginners yo .pptxMS_Excel_Module4.1 ffor beginners yo .pptx
MS_Excel_Module4.1 ffor beginners yo .pptx
 
introductiontospreadsheetapplications-200127165949.pptx
introductiontospreadsheetapplications-200127165949.pptxintroductiontospreadsheetapplications-200127165949.pptx
introductiontospreadsheetapplications-200127165949.pptx
 
Introduction to DAX Language
Introduction to DAX LanguageIntroduction to DAX Language
Introduction to DAX Language
 
Chapter 4 class presentation
Chapter 4 class presentationChapter 4 class presentation
Chapter 4 class presentation
 
Chapter 4 class presentation
Chapter 4 class presentationChapter 4 class presentation
Chapter 4 class presentation
 
Creating & Editing Charts In Microsoft Excel 2003
Creating & Editing Charts In Microsoft Excel 2003Creating & Editing Charts In Microsoft Excel 2003
Creating & Editing Charts In Microsoft Excel 2003
 
MS excel and their functions keys and their usage
MS excel and their functions keys and their usageMS excel and their functions keys and their usage
MS excel and their functions keys and their usage
 
Stanley_Exp22_Excel_Ch03_ML1_Airports.xlsxPassengerTop 6 Unite.docx
Stanley_Exp22_Excel_Ch03_ML1_Airports.xlsxPassengerTop 6 Unite.docxStanley_Exp22_Excel_Ch03_ML1_Airports.xlsxPassengerTop 6 Unite.docx
Stanley_Exp22_Excel_Ch03_ML1_Airports.xlsxPassengerTop 6 Unite.docx
 
Microsoft Excel Glossary & Keyboard Shortcuts-Function Keys
Microsoft Excel Glossary & Keyboard Shortcuts-Function KeysMicrosoft Excel Glossary & Keyboard Shortcuts-Function Keys
Microsoft Excel Glossary & Keyboard Shortcuts-Function Keys
 
Excel Project 2 – MS Excel Summer 2018 Use the project.docx
Excel Project 2 – MS Excel Summer 2018 Use the project.docxExcel Project 2 – MS Excel Summer 2018 Use the project.docx
Excel Project 2 – MS Excel Summer 2018 Use the project.docx
 
WP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightWP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con Silverlight
 
YearQuarterLocationCarClass Revenue NumCars 2017Q1DowntownEconomy.docx
YearQuarterLocationCarClass Revenue   NumCars  2017Q1DowntownEconomy.docxYearQuarterLocationCarClass Revenue   NumCars  2017Q1DowntownEconomy.docx
YearQuarterLocationCarClass Revenue NumCars 2017Q1DowntownEconomy.docx
 

More from Chen Stephen

Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersUpcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersChen Stephen
 
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenTop 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenChen Stephen
 
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenTop 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenChen Stephen
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2Chen Stephen
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2Chen Stephen
 
How to prevent code rot
How to prevent code rotHow to prevent code rot
How to prevent code rotChen Stephen
 
5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web appsChen Stephen
 
A developer's first impressions for windows 8
A developer's first impressions for windows 8A developer's first impressions for windows 8
A developer's first impressions for windows 8Chen Stephen
 
C# insert comments in word
C# insert comments in wordC# insert comments in word
C# insert comments in wordChen Stephen
 

More from Chen Stephen (10)

Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersUpcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
 
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenTop 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
 
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenTop 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2
 
How to prevent code rot
How to prevent code rotHow to prevent code rot
How to prevent code rot
 
5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web apps
 
A developer's first impressions for windows 8
A developer's first impressions for windows 8A developer's first impressions for windows 8
A developer's first impressions for windows 8
 
C# insert comments in word
C# insert comments in wordC# insert comments in word
C# insert comments in word
 
Listview to dif
Listview to difListview to dif
Listview to dif
 

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

C# excel bar chart

  • 1. How to Use C# Create Excel bar Chart Why Create Excel Bar Chart? For numerical comparisons, bar chart is a classic solution. Bar chart (graph) is a chart with rectangular bars with lengths proportional to the values that they represent. The bars can be plotted vertically or horizontally. A bar chart is very useful if you are trying to record certain information whether it is continuous or not continuous data. In bar charts, a class or group can have a single category of data, or they can be broken down further into multiple categories for greater depth of analysis. And in Microsoft Excel, it is the same useful! How to Use C# Create Excel Bar Chart? Spire.XLS for .NET allows user to use C# create Excel bar chart. Use C# to create Excel bar chart could be as easy as in Microsoft Excel. The whole process is almost the same such as write chart data, set region/position of chart, Write chart title, chart data information, etc. The difference is we need fill these data in C# application with codes around. Below is a sample for C# code used to create Excel bar charts. Download Spire.XLS (or Spire.Office) with .NET framework 2.0 (or above) together and use the code to create Excel Bar Chart right now. C# Excel Bar Chart: using Spire.Xls; using Spire.Xls.Charts; namespace Spire.Xls.Sample { class program { static void Main() { Application.Run(new Form1()); } private void btnRun_Click(object sender, System.EventArgs e) { Workbook workbook = new Workbook(); //Initailize worksheet workbook.CreateEmptySheets(1); Worksheet sheet = workbook.Worksheets[0]; sheet.Name = "Chart data"; sheet.GridLinesVisible = false; //Writes chart data CreateChartData(sheet); //Add a new chart worsheet to workbook
  • 2. Chart chart = sheet.Charts.Add(); //Set region of chart data chart.DataRange = sheet.Range["A1:C5"]; chart.SeriesDataFromRange = false; //Set position of chart chart.LeftColumn = 1; chart.TopRow = 6; chart.RightColumn = 11; chart.BottomRow = 29; if (checkBox1.Checked) { chart.ChartType = ExcelChartType.Bar3DClustered; } else { chart.ChartType = ExcelChartType.BarClustered; } //Chart title chart.ChartTitle = "Sales market by country"; chart.ChartTitleArea.IsBold = true; chart.ChartTitleArea.Size = 12; chart.PrimaryCategoryAxis.Title = "Country"; chart.PrimaryCategoryAxis.Font.IsBold = true; chart.PrimaryCategoryAxis.TitleArea.IsBold = true; chart.PrimaryCategoryAxis.TitleArea.TextRotationAngle = 90; chart.PrimaryValueAxis.Title = "Sales(in Dollars)"; chart.PrimaryValueAxis.HasMajorGridLines = false; chart.PrimaryValueAxis.MinValue = 1000; chart.PrimaryValueAxis.TitleArea.IsBold = true; foreach (Charts.ChartSerie cs in chart.Series) { cs.Format.Options.IsVaryColor = true; cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true; }
  • 3. chart.Legend.Position = LegendPositionType.Top; workbook.SaveToFile("Sample.xls"); ExcelDocViewer(workbook.FileName); } private void CreateChartData(Worksheet sheet) { //Country sheet.Range["A1"].Value = "Country"; sheet.Range["A2"].Value = "Cuba"; sheet.Range["A3"].Value = "Mexico"; sheet.Range["A4"].Value = "France"; sheet.Range["A5"].Value = "German"; //Jun sheet.Range["B1"].Value = "Jun"; sheet.Range["B2"].NumberValue = 6000; sheet.Range["B3"].NumberValue = 8000; sheet.Range["B4"].NumberValue = 9000; sheet.Range["B5"].NumberValue = 8500; //Jun sheet.Range["C1"].Value = "Aug"; sheet.Range["C2"].NumberValue = 3000; sheet.Range["C3"].NumberValue = 2000; sheet.Range["C4"].NumberValue = 2300; sheet.Range["C5"].NumberValue = 4200; //Style sheet.Range["A1:C1"].Style.Font.IsBold = true; sheet.Range["A2:C2"].Style.KnownColor = ExcelColors.LightYellow; sheet.Range["A3:C3"].Style.KnownColor = ExcelColors.LightGreen1; sheet.Range["A4:C4"].Style.KnownColor = ExcelColors.LightOrange; sheet.Range["A5:C5"].Style.KnownColor = ExcelColors.LightTurquoise; //Border sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeTop].Color = Color.FromArgb(0, 0, 128); sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin; sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeBottom].Color = Color.FromArgb(0, 0, 128); sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;
  • 4. sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeLeft].Color = Color.FromArgb(0, 0, 128); sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin; sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeRight].Color = Color.FromArgb(0, 0, 128); sheet.Range["A1:C5"].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin; sheet.Range["B2:C5"].Style.NumberFormat = ""$"#,##0"; } private void ExcelDocViewer( string fileName ) { try { System.Diagnostics.Process.Start(fileName); } catch{} } private void btnAbout_Click(object sender, System.EventArgs e) { Close(); } } } After running your application with the code above, you will find an Excel bar Chart is created.
  • 5. More about Spire.XLS Download Spire.XLS Purchase Spire.XLS