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.
- Include the namespace in your class file
- Create Workbook class instance.
- Add some data to worksheet cells with the Cell object’s putValue method.
- Add a SCATTER Chart to the worksheet by calling the Charts collection’s add method, encapsulated in the Worksheet object.
- Access the new Chart object from the Charts collection by passing its index.
- Set the chart’s data source with Chart.setChartDataRange method.
- 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.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Aspose.Cells for Java supports the following Java versions: J2SE 6.0 (1.6), J2SE 7.0 (1.7), or above.
- Get latest version of Aspose.Cells for Java directly from Maven.