title: Change the Chart point color according to value - JFreeChart
body: <p>I have a CSV file which looks like this <a href="https://www.dropbox.com/s/lh7bb2gbenw2q8a/Electrical.csv?dl=0" rel="nofollow noreferrer">(the file can be be downloaded here)</a><br><br> <a href="https://i.stack.imgur.com/U2Oaj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U2Oaj.jpg" alt="enter image description here"></a>
  <br></p>
  
  <p>I want to graph this with time (first column in the spreadsheet) on the X axis and the names of the switches on the Y axis (column headings for all but the first column). I expect to create one point on the Y axis for each column. The column will be horizontal to the X axis but the colors should change according to the values TRUE or FALSE, or 0, 1, 2. </p>
  
  <p>This is what I've developed so far:</p>
  
  <pre><code>package democsv;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  import org.jfree.chart.ChartFactory;
  import org.jfree.chart.ChartPanel;
  import org.jfree.chart.JFreeChart;
  import org.jfree.chart.plot.PlotOrientation;
  import org.jfree.chart.plot.XYPlot;
  import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
  import org.jfree.data.xy.XYDataset;
  import org.jfree.data.xy.XYSeries;
  import org.jfree.data.xy.XYSeriesCollection;
  import org.jfree.ui.ApplicationFrame;
  import org.jfree.ui.RefineryUtilities;
  
  public class DemoCSV extends ApplicationFrame {
  
      public static List&lt;Object&gt; sections = new ArrayList&lt;&gt;();
      public static String[] switchNames = null;
      public static ArrayList&lt;String&gt; time = new ArrayList&lt;&gt;();
      public static ArrayList&lt;ArrayList&lt;String&gt;&gt; datastore = new ArrayList&lt;&gt;();
  
      public DemoCSV(String applicationTitle, String chartTitle) throws IOException {
          super(applicationTitle);
          InputStream in = DemoCSV.class.getResourceAsStream("/files/Electrical.csv");
          InputStream in2 = DemoCSV.class.getResourceAsStream("/files/Electrical.csv");
  
          BufferedReader reader = new BufferedReader(new InputStreamReader(in));
          BufferedReader read = new BufferedReader(new InputStreamReader(in2));
          String line, line2;
          int cnt = 0;
  
          while ((line = reader.readLine()) != null) {
              String[] dataIn = line.split(",");
  
              if (cnt == 0) {
                  switchNames = sNames(dataIn);
              } else if (cnt != 0) {
                  time.add(dataIn[0]);
              }
              cnt++;
          }
  
          cnt = 0;
  
          int dsize = switchNames.length;
  
          while (datastore.size() &lt; dsize) {
              datastore.add(new ArrayList&lt;&gt;());
          }
  
  
          while ((line2 = read.readLine()) != null) {
              String[] dataIn2 = line2.split(",");
  
              if (cnt != 0) {
                  for (int i = 1; i &lt;= dsize; i++) {
                      datastore.get(i - 1).add(dataIn2[i]);
                  }
              }
              cnt++;
          }
  
          for (String sn : switchNames) {
              sections.add(new XYSeries(sn));
          }
  
          JFreeChart xylineChart = ChartFactory.createXYLineChart(
                  chartTitle,
                  "Category",
                  "Score",
                  createDataset(),
                  PlotOrientation.VERTICAL,
                  true, true, false);
  
          ChartPanel chartPanel = new ChartPanel(xylineChart);
          chartPanel.setPreferredSize(new java.awt.Dimension(1366, 768));
          final XYPlot plot = xylineChart.getXYPlot();
          XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
  
          plot.setRenderer(renderer);
          setContentPane(chartPanel);
  
      }
  
      private XYDataset createDataset() {
  
  
          ArrayList&lt;Object&gt; xystore = new ArrayList&lt;&gt;();
  
          for (String sn : switchNames) {
              xystore.add(new XYSeries(sn));
          }
  
          for (int i = 1; i &lt;= switchNames.length; i++) {
              for (String x : time) {
                  double y = Double.parseDouble(x);
                  ((XYSeries)xystore.get(i-1)).add(y, i);
              }
          }
  
          final XYSeriesCollection dataset = new XYSeriesCollection();
          for (Object xy : xystore) {
              dataset.addSeries((XYSeries)xy);
          }
  
          System.out.println(dataset);
          return dataset;
  
      }
  
      public static String[] sNames(String[] names) {
          String[] arr = Arrays.copyOfRange(names, 1, names.length);
          return arr;
  
      }
  
      public static void DataClear() throws IOException, NullPointerException {
  
      }
  
      public static void main(String[] args) throws IOException {
  
          DemoCSV test = new DemoCSV("Test", "second");
  
          test.pack();
          RefineryUtilities.centerFrameOnScreen(test);
          test.setVisible(true);
      }
  }
  </code></pre>
  
  <p>When this runs it generates something looking like this:</p>
  
  <p><a href="https://i.stack.imgur.com/lWEYy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lWEYy.png" alt="graph"></a></p>
  
  <p>I want to change the color of the points when the value in the column in the csv file changes (doesn't matter what the color is, it's the change in colour we want to see when we look at it). If that is not possible, a way to set value to each node would be enough (with a hover effect).</p>