SlideShare a Scribd company logo
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 Tables
Pivot TablesPivot Tables
Pivot Tables
gjonesnemeth
 
Pivot table presentation
Pivot table presentationPivot table presentation
Pivot table presentationSha Tibnjn
 
Pivot table
Pivot tablePivot table
Pivot table
Vijay Perepa
 
Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813
Dave Shannon
 
Charts and pivot tables
Charts and pivot tablesCharts and pivot tables
Charts and pivot tables
UttaraChattopadhyay
 
Vlookup In Excel
Vlookup In ExcelVlookup In Excel
Vlookup In Excel
dinesh takyar
 
Excel Pivot Tables
Excel Pivot TablesExcel Pivot Tables
Excel Pivot Tables
Matt Saragusa
 
Excel Secrets for Search Marketers
Excel Secrets for Search MarketersExcel Secrets for Search Marketers
Excel Secrets for Search Marketers
Chris 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-mumbai
Unmesh 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 University
Parakramesh Jaroli
 
Creating graphs in excel
Creating graphs in excelCreating graphs in excel
Creating graphs in excel
clynnc
 
excel charts
excel chartsexcel charts
excel charts
Aayushi Jain
 
Using excel for randomization 1
Using excel for randomization 1Using excel for randomization 1
Using excel for randomization 1
Oscar 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 excel
orthms
 

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 style
Chen 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.docx
SANSKAR20
 
Spreadsheet for Year 8
Spreadsheet for Year 8Spreadsheet for Year 8
Spreadsheet for Year 8
qistinahJR
 
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
elbanglis
 
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
cravennichole326
 
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 Docs
rickwatkins
 
Rick Watkins Docs
Rick Watkins DocsRick Watkins Docs
Rick Watkins Docs
rickwatkins
 
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
shagunjain2k22phdcs0
 
introductiontospreadsheetapplications-200127165949.pptx
introductiontospreadsheetapplications-200127165949.pptxintroductiontospreadsheetapplications-200127165949.pptx
introductiontospreadsheetapplications-200127165949.pptx
Abhimanyu Verma
 
Introduction to DAX Language
Introduction to DAX LanguageIntroduction to DAX Language
Introduction to DAX Language
Antonios Chatzipavlis
 
Chapter 4 class presentation
Chapter 4 class presentationChapter 4 class presentation
Chapter 4 class presentation
cmurphysvhs
 
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 usage
shumailbashir82
 
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
mckellarhastings
 
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
sdturton
 
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
elbanglis
 
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
MICTT Palma
 
YearQuarterLocationCarClass Revenue NumCars 2017Q1DowntownEconomy.docx
YearQuarterLocationCarClass Revenue   NumCars  2017Q1DowntownEconomy.docxYearQuarterLocationCarClass Revenue   NumCars  2017Q1DowntownEconomy.docx
YearQuarterLocationCarClass Revenue NumCars 2017Q1DowntownEconomy.docx
adampcarr67227
 

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 rot
Chen Stephen
 
5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web apps
Chen 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 8
Chen 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

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 

Recently uploaded (20)

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

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