HTML JPG PDF XML XLSX
  Product Family
XLSX

Create Scatter Charts in Java

High-speed Java library for creating Scatter Charts. This is a professional software solution to import and export XLSX, PDF, and many other formats using Java.

Create Scatter Charts Using Java

How to create Scatter Charts? With Aspose.Cells for Java library, you can easily Scatter Charts programmatically with a few lines of code. Aspose.Cells for Java is capable of building cross-platform applications with the ability to generate, modify, convert, render and print all Excel files. Java Excel API not only convert between spreadsheet formats, it can also render Excel files as images, PDF, HTML, ODS, CSV, SVG, JSON, WORD, PPT and more, thus making it a perfect choice to exchange documents in industry-standard formats. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.

Repository


<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>

Dependency


<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>version of aspose-cells API</version>
<classifier>jdk17</classifier>
</dependency>

How to Create Scatter Charts in Java

Need to create Scatter Charts programmatically? Java developers can easily create Scatter Charts in just a few lines of code.

  1. Include the namespace in your class file
  2. Create Workbook class instance.
  3. Add some data to worksheet cells with the Cell  object’s putValue  method.
  4. Add a SCATTER Chart to the worksheet by calling the Charts  collection’s add  method, encapsulated in the Worksheet  object.
  5. Access the new Chart  object from the Charts collection by passing its index.
  6. Set the chart’s data source with Chart.setChartDataRange method.
  7. Save as Excel or ODS files.
 

Sample code shows how to create Scatter Charts in Java.


// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);

// Adding sample values to cells
Cells cells = worksheet.getCells();
cells.get("A2").putValue("Category1");
cells.get("A3").putValue("Category2");
cells.get("A4").putValue("Category3");

cells.get("B1").putValue("Scatter");
cells.get("B2").putValue(324);
cells.get("B3").putValue(200);
cells.get("B4").putValue(450);

// Adding a Scatter chart to the worksheet
int chartIndex = worksheet.getCharts().add(ChartType.SCATTER, 6, 2, 20, 10);

// Accessing the instance of the newly added chart
Chart chart = worksheet.getCharts().get(chartIndex);

// Setting chart data source as the range "A1:B4"
chart.setChartDataRange("A1:B4", true);

// Save the Workbook as .xlsx file.
workbook.save("output.xlsx");
 

Java library to create Scatter Charts

We host our Java packages in Maven repositories. ‘Aspose.Cells for Java’ is a common JAR file containing byte-code. Please follow the step-by-step instructions on how to install it to your Java developer environment.

System Requirements

Before running the Java conversion sample source code, make sure that you have the following prerequisites.