Excel Charts uses graphics to present data information to enable users to analyze data more intuitively. According to details of data information, users need to choose the most appropriate chart type. For example, column chart is suitable for comparison between data, while pie chart is often used to show percentage of each item among all.
Spire.XLS for .NET, a stand-alone Excel operation component designed for .NET developers, allows users to generate Excel chart, and this guide will show you how to generate excel column chart with C#, VB.NET via Spire.XLS for .NET. Users can use sheet.Charts.Add(ExcelChartType) method to add chart in Excel. Then, assign value for DataRange property of Chart class to fill information in chart area. Next, set position, chart title, axes, legend and format them for chart to make the chart be more completed and wonderful.
The following screenshot shows the result of Excel column chart generation.
Download and install Spire.XLS for .NET. Use the following code to generate Excel column chart.
using System.Drawing; using Spire.Xls; namespace XLSTest { class Program { static void Main(string[] args) { //Load Workbook Workbook workbook = new Workbook(); workbook.LoadFromFile(@"E:\Work\Documents\ExcelFiles\PartSalesInfo.xlsx"); Worksheet sheet = workbook.Worksheets[0]; //Add Chart and Set Chart Data Range Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered); chart.DataRange = sheet.Range["D1:E17"]; chart.SeriesDataFromRange = false; //Chart Position chart.LeftColumn = 1; chart.TopRow = 19; chart.RightColumn = 8; chart.BottomRow = 33; //Chart Border chart.ChartArea.Border.Weight = ChartLineWeightType.Medium; chart.ChartArea.Border.Color = Color.SandyBrown; //Chart Title chart.ChartTitle = "Parts Sales Info"; chart.ChartTitleArea.Font.FontName = "Calibri"; chart.ChartTitleArea.Font.Size = 13; chart.ChartTitleArea.Font.IsBold = true; //Chart Axes chart.PrimaryCategoryAxis.Title = "Parts"; chart.PrimaryCategoryAxis.Font.Color = Color.Blue; chart.PrimaryValueAxis.Title = "Amounts"; chart.PrimaryValueAxis.HasMajorGridLines = false; chart.PrimaryValueAxis.MaxValue = 350; chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90; //Chart Legend chart.Legend.Position = LegendPositionType.Right; //Save and Launch workbook.SaveToFile("ExcelColumnChart.xlsx",ExcelVersion.Version2010); System.Diagnostics.Process.Start("ExcelColumnChart.xlsx"); } } }
Imports System.Drawing Imports Spire.Xls Namespace XLSTest Friend Class Program Shared Sub Main(ByVal args() As String) 'Load Workbook Dim workbook As New Workbook() workbook.LoadFromFile("E:\Work\Documents\ExcelFiles\PartSalesInfo.xlsx") Dim sheet As Worksheet = workbook.Worksheets(0) 'Add Chart and Set Chart Data Range Dim chart As Chart = sheet.Charts.Add(ExcelChartType.ColumnClustered) chart.DataRange = sheet.Range("D1:E17") chart.SeriesDataFromRange = False 'Chart Position chart.LeftColumn = 1 chart.TopRow = 19 chart.RightColumn = 8 chart.BottomRow = 33 'Chart Border chart.ChartArea.Border.Weight = ChartLineWeightType.Medium chart.ChartArea.Border.Color = Color.SandyBrown 'Chart Title chart.ChartTitle = "Parts Sales Info" chart.ChartTitleArea.Font.FontName = "Calibri" chart.ChartTitleArea.Font.Size = 13 chart.ChartTitleArea.Font.IsBold = True 'Chart Axes chart.PrimaryCategoryAxis.Title = "Parts" chart.PrimaryCategoryAxis.Font.Color = Color.Blue chart.PrimaryValueAxis.Title = "Amounts" chart.PrimaryValueAxis.HasMajorGridLines = False chart.PrimaryValueAxis.MaxValue = 350 chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90 'Chart Legend chart.Legend.Position = LegendPositionType.Right 'Save and Launch workbook.SaveToFile("ExcelColumnChart.xlsx", ExcelVersion.Version2010) System.Diagnostics.Process.Start("ExcelColumnChart.xlsx") End Sub End Class End Namespace