Create Excel Scatter Chart
IronXL supports creation and editing of Charts for Excel documents in the modern XLSX file format.
This example shows how to create a Scatter Chart. Other chart types are also supported.
using IronXL; using IronXL.Drawing.Charts; WorkBook workbook = WorkBook.Load("test.xlsx"); WorkSheet sheet = workbook.DefaultWorkSheet; //Set the chart type and it's position on the worksheet. var chart = sheet.CreateChart(ChartType.Scatter, 10, 2, 18, 5); //Add the series to the chart //Both axes of the scatter chart are value axes. //The first parameter is the address of the range for horizontal(value) axis. //The second parameter is the address of the range for vertical(value) axis. var series = chart.AddSeries("B3:B8", "A3:A8"); var rnd = new Random(); foreach (var cell in sheet["C3:C8"]) { //Populate one more column with random values cell.Value = rnd.Next(10); } //For scatter chart there is an option to to add set of data only for vertical axis. chart.AddSeries("C3:C8"); //The set of data in the horizontal axis starts from one in ascending order. //Set the chart title. series.Title = "Scatter Chart"; //Set the legend position. //Can be removed by setting it to None. chart.SetLegendPosition(LegendPosition.Top); //Plot all the data that was added to the chart before. //Multiple call of this method leads to plotting multiple charts instead of modyfying the existing chart. //Yet there is no possibility to remove chart or edit it's series/position. //We can just create new one. chart.Plot(); workbook.SaveAs("CreateScatterChart.xlsx");
Imports IronXL Imports IronXL.Drawing.Charts Private workbook As WorkBook = WorkBook.Load("test.xlsx") Private sheet As WorkSheet = workbook.DefaultWorkSheet 'Set the chart type and it's position on the worksheet. Private chart = sheet.CreateChart(ChartType.Scatter, 10, 2, 18, 5) 'Add the series to the chart 'Both axes of the scatter chart are value axes. 'The first parameter is the address of the range for horizontal(value) axis. 'The second parameter is the address of the range for vertical(value) axis. Private series = chart.AddSeries("B3:B8", "A3:A8") Private rnd = New Random() For Each cell In sheet("C3:C8") 'Populate one more column with random values cell.Value = rnd.Next(10) Next cell 'For scatter chart there is an option to to add set of data only for vertical axis. chart.AddSeries("C3:C8") 'The set of data in the horizontal axis starts from one in ascending order. 'Set the chart title. series.Title = "Scatter Chart" 'Set the legend position. 'Can be removed by setting it to None. chart.SetLegendPosition(LegendPosition.Top) 'Plot all the data that was added to the chart before. 'Multiple call of this method leads to plotting multiple charts instead of modyfying the existing chart. 'Yet there is no possibility to remove chart or edit it's series/position. 'We can just create new one. chart.Plot() workbook.SaveAs("CreateScatterChart.xlsx")
IronXL supports creation and editing of Charts for Excel documents in the modern XLSX file format.
This example shows how to create a Scatter Chart. Other chart types are also supported.