I have a graph showing the lines in 3 colours (red, green, blue), like screenshot.
When I press one of the colours, i.e. red, I want to show graph with only red colour. And if I press green then only green. But if I press nothing then it should show all.
Below my code for creating and drawing the lines.
import java.awt.Color;
import java.io.FileInputStream;
import javax.swing.JOptionPane;
import javax.swing.JScrollBar;
import javax.swing.SwingConstants;
import java.io.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
class LineGraph extends ApplicationFrame {
private JFreeChart createChart(final XYDataset dataset) {
// Graph wird erstellt...
final JFreeChart chart = ChartFactory.createXYLineChart("","X","Y",dataset,PlotOrientation.VERTICAL,true,false,false);
final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
NumberAxis xAxis = (NumberAxis) plot.getRangeAxis();
xAxis.setRange (0, 7500);
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
yAxis.setRange(0, 270);
return chart;
}
public LineGraph(final String title) {
super(title);
}
public ChartPanel createPanel(final String title){
final XYDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(950, 570));
//chartPanel.setSize(50, 50);
//setContentPane(chartPanel);
return chartPanel;
}
private XYSeriesCollection createDataset() {
try {
final int pictureWidth = 7500;
final int pictureHeight = 5;
int pictureArray[] = new int[pictureWidth * pictureHeight];
int pixArray[] = new int[pictureWidth];
int R, G, B, U;
int averageX, averageY;
FileInputStream inp = new FileInputStream("d:\\DO_18-02-2014_19-59-05-756_00010.img");
int k = 0;
XYSeries RED = new XYSeries("R");
XYSeries GREEN = new XYSeries("G");
XYSeries BLUE = new XYSeries("B");
XYSeries UNDEFINED = new XYSeries("U");
for (int j = 0; j < pictureHeight; j++)
{for (int i = 0; i < pictureWidth; i++)
{ R = inp.read();
G = inp.read();
B = inp.read();
U = inp.read();
Color c = new Color(R, G, B, U);
pictureArray[k++] = c.getRGB();
System.out.println((new Integer(i)).toString()+" "+(new Integer(j)).toString());
RED.add(i, R);
GREEN.add(i, B);
BLUE.add(i, G);
UNDEFINED.add(i, U);
}
}
inp.close();
final XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(RED);
dataset.addSeries(GREEN);
dataset.addSeries(BLUE);
dataset.addSeries(UNDEFINED);
return dataset;
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, e, "Exception Raised",
JOptionPane.INFORMATION_MESSAGE);
return null;
}
}
}
And below the code for the combobox.
![//Create ComboBox for RGB Choice
String ChannelStrings\[\] = { "All", "Red", "Green", "Blue"};
JComboBox ChannelChoice = new JComboBox(ChannelStrings);
ChannelChoice.setFont((new Font ("Arial", Font.BOLD, 13)));
panelButton.add(ChannelChoice);][1]