How to update Scatter Plot as the new value comes

A discussion forum for JFreeChart (a 2D chart library for the Java platform).

How to update Scatter Plot as the new value comes

Postby kalu » Mon Jan 15, 2018 4:49 pm

Hi, I want to update the value of scatter plot of below examples. But i am not able to do it. Please see the code and suggest me how to do it. Thanks in advance for the help.

public class EnergyTest extends JFrame{

private static final long serialVersionUID = 6294689542092367723L;

public EnergyTest(String title) {

// Create dataset
XYDataset dataset = createDataset();

// Create chart
JFreeChart chart = ChartFactory.createScatterPlot(
"Boys VS Girls weight comparison chart",
"X-Axis", "Y-Axis", dataset);

//Changes background color
XYPlot plot = (XYPlot)chart.getPlot();
plot.setBackgroundPaint(new Color(255,228,196));

// Create Panel
ChartPanel panel = new ChartPanel(chart);
double time = 0;
private XYDataset createDataset(){
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series1 = new XYSeries("Boys");
Components components = JSensors.get.components();
List<Cpu> cpus = components.cpus;
if (cpus != null) {
for (final Cpu cpu : cpus) {
if (cpu.sensors != null) {
List<Temperature> temps = cpu.sensors.temperatures;
for (final Temperature temp : temps) {
switch( {
case("Temp CPU Core #1") :
series1.add(++time, temp.value);
case("Temp CPU Core #2") :
continue restart;
case("Temp CPU Package") :
continue restart;
return dataset;


public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
EnergyTest example = new EnergyTest("Scatter Chart Example | BORAJI.COM");
example.setSize(800, 400);
Posts: 1
Joined: Mon Jan 15, 2018 4:39 pm

Re: How to update Scatter Plot as the new value comes

Postby John Matthews » Tue Jan 16, 2018 12:22 am

In this complete example, a button's ActionListener updates an XYSeries named added. The listening plot updates itself in response.
John Matthews
Posts: 401
Joined: Wed Sep 12, 2007 3:18 pm

Return to JFreeChart

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests