SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
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
 
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
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 

Kürzlich hochgeladen (20)

Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
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
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
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
 
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...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 

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