I have an issue with my jfreechart graph. Actually at x-axis the value are in big numbers (i-e 1500-2000) and the amounts of these values are also too large (i.e in significant notation).So the chart is just showing a dashed line instead of values at x-axis.
public static byte[] createImageByXyChart(String str_chartLabel,
String str_xAxisLabel, String str_yAxisLabel,
String str_fileFormat, Integer i_height, Integer i_width,
List<double[]> co_ordinates) throws IOException {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (int i = 0; i < co_ordinates.size(); i++) {
double[] xy_coOrdinates = co_ordinates.get(i);
double xCoordiate = xy_coOrdinates[0];
double yCoordiate = xy_coOrdinates[1];
dataset.setValue(yCoordiate, str_chartLabel, "" + xCoordiate);
}
JFreeChart chart =
ChartFactory.createLineChart(str_chartLabel,str_xAxisLabel,
str_yAxisLabel, dataset);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setRangePannable(true);
plot.setRangeGridlinesVisible(true);
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlineStroke(new BasicStroke(1.0f));
plot.setRangeGridlineStroke(new BasicStroke(1.0f));
plot.setDomainGridlinePaint(Color.GRAY.brighter());
plot.setRangeGridlinePaint(Color.GRAY.brighter());
ChartPanel panel = new ChartPanel(chart);
JFrame frame = new JFrame("Show chart");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.setSize(600, 600);
frame.setVisible(true);
return null;
}
public static void main(String[] arg) throws Exception {
System.out.println("########################### ");
File fileData = new File("curve.txt");
BufferedReader br = new BufferedReader(new FileReader(fileData));
List<double[]> co_ordinates = new ArrayList<double[]>();
String line = null;
while ((line = br.readLine()) != null) {
String[] abcd = line.split(",");
double[] xy_cor = new double[2];
NumberFormat df = new DecimalFormat("######.####");
xy_cor[0] = Double.parseDouble(df.format(Double
.parseDouble(abcd[0])));
System.out.println(xy_cor[0]);
xy_cor[1] = Double.parseDouble(abcd[1]);
System.out.println(Arrays.toString(xy_cor));
co_ordinates.add(xy_cor);
}
br.close();
String str_chartLaber = "Curve";
String str_xAxisLabel = "Time(s)";
String str_yAxisLaber = "Accelaration (mm_per__s_2)";
String str_fileFormate = ImageFormats.JPEG;
Integer heigth = 1800;
Integer width = 1080;
byte[] image_bytes = ImageUtils.createImageByXyChart(str_chartLaber,
str_xAxisLabel, str_yAxisLaber, str_fileFormate, heigth, width,
co_ordinates);
}
the input data is that
Heading
i use
XYDataset dataset ;
instead of
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
The XYDataset enable auto interval where DefaultCategoryDataset do not.I don't know the reason but it is.
Related
I have a JavaFX program the uses TableView and shapes and lines.
My question is I want the shapes and lines to refresh when I click on a cell and I did that but now it prints over the previous cell I clicked on.
Here is the window screenshot
When I click on another cell
Here is the piece of code
public class SettingData extends Application {
public int differenceInDays1=0;
BorderPane border = new BorderPane();
Line line = new Line();
Group group = new Group();
public void start(Stage stage) throws IOException {
// label of the project
Label lineLabel = new Label("Project ID: ");
// text for the chosen project
Text text = new Text();
Text startDate = new Text();
Text EndDate = new Text();
Font font = Font.font(Font.getFamilies().get(25), FontWeight.BOLD, FontPosture.REGULAR, 50);
text.setFont(font);
//array of projects
readExcel excelObj = new readExcel();
ObservableList<projects> data = FXCollections.observableList(excelObj.projectsArrMaker());
// creating tableView
TableView<projects> table = new TableView<projects>(data);
table.setPrefSize(300, 900);
Label label = new Label("Project ID");
//Creating columns
TableColumn<projects, String> projIDCol = new TableColumn("Project ID");
projIDCol.setCellValueFactory(new PropertyValueFactory<>("ProjectID"));
table.getColumns().add(projIDCol);
TableColumn<projects, String> stagesCol = new TableColumn("Stages");
stagesCol.setCellValueFactory(new PropertyValueFactory<>("Stage"));
table.getColumns().add(stagesCol);
//array of projects details
ArrayList<projectsDetails> projDeatailsArr = excelObj.detailsArrMaker();
// set action
table.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (newValue != null) {
// setting texts for the chosen node
text.setText(newValue.getProjectID());
label.setText(newValue.getProjectID());
String sdateFormat = "yyyy-MM-dd";
DateFormat dateFormat = new SimpleDateFormat(sdateFormat);
//start date
String StringSD = dateFormat.format(newValue.getStartDate());
startDate.setText(StringSD);
// end date
String StringED = dateFormat.format(newValue.getEndDate());
EndDate.setText(StringED);
//System.out.print(newValue.getStartDate().getMonth());
//difference between start and end date
long difference = newValue.getEndDate().getTime() - newValue.getStartDate().getTime();
long differenceInDays = (difference / (1000 * 60 * 60 * 24)) % 365;
//System.out.print(differenceInDays);
long diffInYears = newValue.getEndDate().getYear()-newValue.getStartDate().getYear();
differenceInDays1 = (int) ((differenceInDays) + (diffInYears * 365));
System.out.print(differenceInDays1);
//vertical lines HBox
////////////////////////////////////////////////////////////////////
for(int i = 0; i< differenceInDays1 %30 ; i++) {
Line large = new Line();
large.setStartX(400+i*90);
large.setEndX(400+i*90);
large.setStartY(495);
large.setEndY(505);
for(int j=0; j<30 ; j++) {
Line small = new Line();
small.setStartX(400+j*3+i*90);
small.setEndX(400+j*3+i*90);
small.setStartY(498);
small.setEndY(500);
group.getChildren().add(small);
}
group.getChildren().add(large);
Rectangle rect = new Rectangle(450,490,5,5);
group.getChildren().add(rect);
}
// array of events dates
//ArrayList<java.util.Date> eventsDate = new ArrayList<java.util.Date>();
// loop through the details
for(projectsDetails proj : projDeatailsArr) {
if(proj.getObjectValue().equals(newValue.getNodeID())) {
proj.getStageDate().getMonth();
//long horizontal line
line.setStartX(400);
line.setEndX(1300);
//line VBox
VBox lineBox = new VBox(line);
lineBox.setAlignment(Pos.CENTER);
////////////////////////////////////////////////////////////////////
group.getChildren().addAll(line);
lineLabel.relocate(350, 100);
text.relocate(420, 80);
line.setLayoutY(500);
startDate.relocate(350, 520);
EndDate.relocate(1350, 520);
}
}
}
});
//vertical lines HBox
////////////////////////////////////////////////////////////////////
for(int i = 0; i< differenceInDays1 %30 ; i++) {
Line large = new Line();
large.setStartX(400+i*90);
large.setEndX(400+i*90);
large.setStartY(495);
large.setEndY(505);
for(int j=0; j<30 ; j++) {
Line small = new Line();
small.setStartX(400+j*3+i*90);
small.setEndX(400+j*3+i*90);
small.setStartY(498);
small.setEndY(500);
group.getChildren().add(small);
}
group.getChildren().add(large);
Rectangle rect = new Rectangle(450,490,5,5);
group.getChildren().add(rect);
}
//Setting the scene
Pane pane = new Pane(table, lineLabel, text, line,group, startDate, EndDate);
Scene scene = new Scene(pane, 2000, 2000);
stage.setTitle("Table View Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
I have produced a line graph like this. Even though there are no zero data for the blue line and also the red line only have the value until 100. So how do i set the blue line to start at zero and red to finish until 200 like this:
My data in textfile (outputAvgGen.txt) are:
11752.58,HC
11819.65,HC
11941.75,HC
12398.45,HC
12401.06,HC
12531.09,HC
12634.33,HC
12748.83,HC
12787.36,HC
12799.44,HC
.
.
.
30137.15,P3
31919.46,P3
32323.8,P3
.
.
.
and so on until 200 data
This is my code:
public class Graph2 extends JFrame{
public Graph2(){
setTitle("P3 Performance Analysis");
JPanel chartPanel = createChartPanel();
add(chartPanel, BorderLayout.CENTER);
setSize(640, 480);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new Graph2().setVisible(true);
}
});
}
private JPanel createChartPanel() {
// creates a line chart object
// returns the chart panel
String chartTitle = "Average Fitness against No. of Generations";
String xAxisLabel = "No. of Generations";
String yAxisLabel = "Average Fitness";
XYDataset dataset = createDataset();
JFreeChart chart = ChartFactory.createXYLineChart(chartTitle,
xAxisLabel, yAxisLabel, dataset);
XYPlot plot = chart.getXYPlot();
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
yAxis.setAutoRangeIncludesZero(true);
return new ChartPanel(chart);
}
private XYDataset createDataset() {
ArrayList<PlotData2> dataList = readData();
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series1 = new XYSeries("Hill Climber");
XYSeries series2 = new XYSeries("P3");
for (int i = 0; i < dataList.size(); i++){
if (dataList.get(i).getAlgo().equals("HC")){
series1.add(i, dataList.get(i).getAvg());
System.out.println("HC i=" + i);
}
else if (dataList.get(i).getAlgo().equals("P3")){
series2.add(i, dataList.get(i).getAvg());
System.out.println("P3 i=" + i);
}
}
/*
for (int i = 0; i < dataList.size(); i++){
if (dataList.get(i).getAlgo().equals("HC")){
System.out.println("i = " + i);
series1.add(i, dataList.get(i).getAvg());
}
}
for (int j = 0; j < dataList.size(); j++){
if (dataList.get(j).getAlgo().equals("P3")){
System.out.println("j = " + j);
series2.add(j, dataList.get(j).getAvg());
}
}*/
/*
series1.add(1.0, 2.0);
series1.add(2.0, 3.0);
series1.add(3.0, 2.5);
series1.add(3.5, 2.8);
series1.add(4.2, 6.0);
series2.add(2.0, 1.0);
series2.add(2.5, 2.4);
series2.add(3.2, 1.2);
series2.add(3.9, 2.8);
series2.add(4.6, 3.0); */
dataset.addSeries(series1);
dataset.addSeries(series2);
return dataset;
}
public static ArrayList<PlotData2> readData(){
ArrayList<PlotData2> dataList = new ArrayList<PlotData2>();
try {
BufferedReader in = new BufferedReader( new FileReader("outputAvgGen.txt") );
String str;
while ( (str = in.readLine() )!= null ) {
String[] data = str.split( "," );
double avg = Double.parseDouble(data[0]);
String algo = data[1];
// int gen = Integer.parseInt(data[2]);
dataList.add(new PlotData2(algo,avg));
}
in.close();
} catch ( IOException ex ) {
System.err.println( "Error: Can't open the file for reading." );
}
return dataList;
}
}
Actually my original data being computed are in pairs of HC and P3 in a textfile like this:
15426.35,HC
38903.93,P3
13777.49,HC
34480.21,P3
15199.38,HC
38559.36,P3
13399.15,HC
32931.49,P3
.
.
and so on..
but I sorted it to make the graph being plotted ascendingly but when sorted it doesn't plot according to the pairs.
Can someone please help with the code at least to make it start at zero and end at max range for both lines to make it look simultaneous. Thank you.
The major issue with your code is that you are incrementing the x values for both series simultaneously. You need to do that separately. Furthermore, you are using hardcoded strings in your createDataset method.
Try this approach instead:
public static HashMap<String, List<Double>> readData() {
HashMap<String, List<Double>> dataList = new HashMap<String, List<Double>>();
try {
BufferedReader in = new BufferedReader(new FileReader("outputAvgGen.txt"));
String str;
while ((str = in.readLine()) != null) {
String[] data = str.split(",");
String algo = data[1];
if (dataList.get(algo) == null) {
dataList.put(algo, new ArrayList<Double>());
}
dataList.get(algo).add(Double.parseDouble(data[0]));
}
in.close();
}
catch (IOException ex) {
System.err.println("Error: Can't open the file for reading.");
}
return dataList
}
private XYDataset createDataset() {
HashMap<String, List<Double>> dataList = readData();
XYSeriesCollection dataset = new XYSeriesCollection();
Set<String> keys = dataList.keySet();
for (String key : keys) {
XYSeries series = new XYSeries(key);
List<Double> numbers = dataList.get(key);
for (int i = 0; i < numbers.size() - 1; i++) {
series.add(i, numbers.get(i), false);
}
series.add(numbers.size() - 1, numbers.get(numbers.size() - 1), true);
dataset.addSeries(series);
}
return dataset;
}
My program is up and working like I wanted it but now I want to implement Runnable in my program so I could show each tab that my chart runs. How should I do this? I've tried using the methods that I did before but I could not correlate it into my program.
public class Induction {
final static String titles[] = {"A","B","C","S", "SH", "W"};
private final static TimeSeriesCollection all = new TimeSeriesCollection();
static Day day = new Day(9,7,2014);
private static TimeSeriesCollection createInduction() {
for (String s : titles) {
all.addSeries(new TimeSeries(s));
}
// while parsing the CSV file
String zone = "/home/a002384/ECLIPSE/IN070914.CSV";
TimeSeries ts = all.getSeries(zone);
TreeMap<String, TreeMap<Integer, Integer[]>> zoneMap = new TreeMap<String, TreeMap<Integer, Integer[]>>();
try{
BufferedReader bufferedReader = new BufferedReader(new FileReader(zone));
String line;
try {
// Read a line from the csv file until it reaches to the end of the file...
while ((line = bufferedReader.readLine()) != null)
{
// Parse a line of text in the CSV
String [] indData = line.split("\\,");
long millisecond = Long.parseLong(indData[0]);
String zones = indData[1];
// The millisecond value is the # of milliseconds since midnight
// From this, we can derive the hour and minute of the day
// as follows:
int secOfDay = (int) (millisecond / 1000);
int hrOfDay = secOfDay / 3600;
int minInHr = secOfDay % 3600 / 60;
// Obtain the induction rate TreeMap for the current zone
// If this is a "newly-encountered" zone, create a new TreeMap
TreeMap<Integer, Integer[]> hourCountsInZoneMap;
if (zoneMap.containsKey(zones))
hourCountsInZoneMap = zoneMap.get(zones);
else
hourCountsInZoneMap = new TreeMap<Integer, Integer[]>();
// Obtain the induction rate array for the current hour
// in the current zone.
// If this is a new hour in the current zone, create a
// new array, and initialize this array with all zeroes.
// The array is size 60, because there are 60 minutes in
// the hour. Each element in the array represents the
// induction rate for that minute
Integer [] indRatePerMinArray;
if (hourCountsInZoneMap.containsKey(hrOfDay))
indRatePerMinArray = hourCountsInZoneMap.get(hrOfDay);
else
{
indRatePerMinArray = new Integer[60];
Arrays.fill(indRatePerMinArray, 0);
}
// Increment the induction rate for the current minute
// by one. Each line in the csv file represents a
// single induction at a single point in time
indRatePerMinArray[minInHr]++;
// Add everything back into the TreeMaps if these are
// newly created.
if (!hourCountsInZoneMap.containsKey(hrOfDay))
hourCountsInZoneMap.put(hrOfDay, indRatePerMinArray);
if (!zoneMap.containsKey(zones))
zoneMap.put(zones, hourCountsInZoneMap);
}
}
finally
{
bufferedReader.close();
}
}
catch (Exception e){
e.printStackTrace();
}
// Iterate through all zones and print induction rates
// for every minute into every hour by zone ...
Iterator<String> zoneIT = zoneMap.keySet().iterator();
while (zoneIT.hasNext())
{
String zones2 = zoneIT.next();
TreeMap<Integer, Integer[]> hourCountsInZoneMap = zoneMap.get(zones2);
System.out.println("ZONE " + zones2 + ":");
Iterator<Integer> hrIT = hourCountsInZoneMap.keySet().iterator();
while (hrIT.hasNext())
{
int hour = hrIT.next();
Integer [] indRatePerMinArray = hourCountsInZoneMap.get(hour);
for (int i = 0; i < indRatePerMinArray.length; i++)
{
System.out.print(hour + ":");
System.out.print(i < 10 ? "0" + i : i);
System.out.println(" = " + indRatePerMinArray[i] + "induction(s)");
}
}
}
TimeSeries s1 = new TimeSeries("A");
TreeMap<Integer, Integer[]> dayAZone = zoneMap.get("A");
Iterator<Integer> hourIT = dayAZone.keySet().iterator();
while (hourIT.hasNext())
{
Integer indHour = hourIT.next();
Hour hour = new Hour(indHour, day);
Integer [] indMins = dayAZone.get(indHour);
for (int i = 0; i < 60; i++)
s1.addOrUpdate(new Minute(i, hour), indMins[i]);
System.out.println(zoneMap);
}
TimeSeries s2 = new TimeSeries("B");
TreeMap<Integer, Integer[]> dayBZone = zoneMap.get("B");
Iterator<Integer> hourIT1 = dayBZone.keySet().iterator();
while (hourIT1.hasNext())
{
Integer indHour = hourIT1.next();
Hour hour = new Hour(indHour, day);
Integer [] indMins = dayBZone.get(indHour);
for (int i = 0; i < 60; i++)
s2.addOrUpdate(new Minute(i, hour), indMins[i]);
System.out.println(zoneMap);
}
TimeSeries s3 = new TimeSeries("C");
TreeMap<Integer, Integer[]> dayCZone = zoneMap.get("C");
Iterator<Integer> hourIT2 = dayCZone.keySet().iterator();
while (hourIT2.hasNext())
{
Integer indHour = hourIT2.next();
Hour hour = new Hour(indHour, day);
Integer [] indMins = dayCZone.get(indHour);
for (int i = 0; i < 60; i++)
s3.addOrUpdate(new Minute(i, hour), indMins[i]);
System.out.println(zoneMap);
}
TimeSeries s4 = new TimeSeries("S");
TreeMap<Integer, Integer[]> daySZone = zoneMap.get("S");
Iterator<Integer> hourIT3 = daySZone.keySet().iterator();
while (hourIT3.hasNext())
{
Integer indHour = hourIT3.next();
Hour hour = new Hour(indHour, day);
Integer [] indMins = daySZone.get(indHour);
for (int i = 0; i < 60; i++)
s4.addOrUpdate(new Minute(i, hour), indMins[i]);
System.out.println(zoneMap);
}
TimeSeries s5 = new TimeSeries("SH");
TreeMap<Integer, Integer[]> daySHZone = zoneMap.get("SH");
Iterator<Integer> hourIT4 = daySHZone.keySet().iterator();
while (hourIT4.hasNext())
{
Integer indHour = hourIT4.next();
Hour hour = new Hour(indHour, day);
Integer [] indMins = daySHZone.get(indHour);
for (int i = 0; i < 60; i++)
s5.addOrUpdate(new Minute(i, hour), indMins[i]);
System.out.println(zoneMap);
}
TimeSeries s6 = new TimeSeries("W");
TreeMap<Integer, Integer[]> dayWZone = zoneMap.get("W");
Iterator<Integer> hourIT5 = dayWZone.keySet().iterator();
while (hourIT5.hasNext())
{
Integer indHour = hourIT5.next();
Hour hour = new Hour(indHour, day);
Integer [] indMins = dayWZone.get(indHour);
for (int i = 0; i < 60; i++)
s6.addOrUpdate(new Minute(i, hour), indMins[i]);
System.out.println(zoneMap);
}
all.addSeries(s1);
all.addSeries(s2);
all.addSeries(s3);
all.addSeries(s4);
all.addSeries(s5);
all.addSeries(s6);
return all;
}
private static ChartPanel createPane(String title) {
TimeSeriesCollection dataset = new ``TimeSeriesCollection(all.getSeries(title));
int j = 0;
JFreeChart chart = ChartFactory.createXYBarChart(
"Induction Chart Zone ",
"Hour",
true,
"Inductions Per Minute",
dataset,
PlotOrientation.VERTICAL,
false,
true,
false
);
XYPlot plot = (XYPlot)chart.getPlot();
XYBarRenderer renderer = (XYBarRenderer)plot.getRenderer();
renderer.setBarPainter(new StandardXYBarPainter());
renderer.setDrawBarOutline(false);
// Set an induction of 30 per minute...
Marker target = new ValueMarker(30);
target.setPaint(java.awt.Color.blue);
target.setLabel("Rate");
plot.addRangeMarker(target);
return new ChartPanel(chart);
}
public static void main(String[] args) {
createInduction();
final JFrame frame = new JFrame("Induction Zone Chart");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTabbedPane jtp = new JTabbedPane();
final int j = 0;
jtp.add(titles[j], createPane("A"));
jtp.add(titles[j+1], createPane("B"));
jtp.add(titles[j+2], createPane("C"));
jtp.add(titles[j+3], createPane("S"));
jtp.add(titles[j+4], createPane("SH"));
jtp.add(titles[j+5], createPane("W"));
for (String s : titles) {
jtp.add(createPane(s));
}
jtp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
ChartPanel chart = null;
for (int i = 0; i < titles.length; i++)
{
chart = createPane(titles[i].substring(1, titles[i].length()));
}
final JPanel p = new JPanel(new FlowLayout(FlowLayout.RIGHT));
p.add(new JButton(new AbstractAction("Update") {
/**
*
*/
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
frame.repaint();
}
}));
ChangeListener changeListener = new ChangeListener() {
public void stateChanged(ChangeEvent changeEvent) {
JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
int index = sourceTabbedPane.getSelectedIndex();
String tabTitle = sourceTabbedPane.getTitleAt(index);
createPane(tabTitle.substring(0, tabTitle.length()));
System.out.println("Source to " + tabTitle);
}
};
while (jtp.getTabCount() > 6)
jtp.remove(6);
jtp.addChangeListener(changeListener);
frame.add(jtp, BorderLayout.CENTER);
frame.add(p, BorderLayout.SOUTH);
frame.setPreferredSize(new Dimension(1000, 600));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Update each chart's model, an instance of TimeSeries, in the background of a SwingWorker. A complete example is shown here. The listening view, an instance of ChartPanel, will update itself accordingly.
I am new to android, and I have to create an app that plots data. One set of data is about 7000 data point, and I've been using AChartEngine. I am using an ArrayList to hold the data.
ArrayList<Double> forehead = new ArrayList<Double>();
private XYMultipleSeriesDataset getforeDataset() {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYSeries firstSeries = new XYSeries("Forehead");
for (int i = 0; i < forehead.size(); i++)
firstSeries.add(i, forehead.get(i));
dataset.addSeries(firstSeries);
return dataset;
this is where I add data into the ArrayList, a sample string that would be read in is:
"02888 0 096 098 080"
private void getIntegerArray(ArrayList<String> stringArray) {
for (String s:stringArray){
String[] str = s.split("\t");
forehead.add(Double.parseDouble(str[3]));
}
}
private XYMultipleSeriesRenderer getforeRenderer() {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setMargins(new int[] { 0, 0, 0, 0 });
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.BLUE);
r.setPointStyle(PointStyle.POINT);
r.setFillPoints(false);
renderer.addSeriesRenderer(r);
return renderer;
}
plotting
mChartView2 = ChartFactory.getLineChartView(getActivity(), getforeDataset(),
getforeRenderer());
layout2.addView(mChartView2);
Here is my application and no data is displayed, how can I display the 'forehead' ArrayList?
http://imgur.com/aYyDVnL
Use this
String[] str = s.split(" ");
instead of
String[] str = s.split("\t");
I think you are not getting the values as you want.
im working with jfreechart and try to make a XYLineChart which is working very well.
My problem is, that the y label are double values and i need strings.
My Code:
DefaultXYDataset result = new DefaultXYDataset();
XYSeries series1 = new XYSeries("Words");
series1.add(0, 0.3);
series1.add(1, 0.5);
series1.add(2, 0.6);
series1.add(3, 0.3);
series1.add(4, 0.2);
series1.add(5, 1);
result.addSeries(getTitle(), series1.toArray());
I want something like:
XYSeries series1 = new XYSeries("Words");
series1.add("word 1", 0.3);
series1.add("word 2", 0.5);
...
The updated code using Symbol-Axis:
private void test2() {
XYDataset dataset = createDataset2();
JFreeChart chart = createChart2(dataset, "NN");
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 250));
panel_visualize.add(chartPanel);
}
private DefaultXYDataset createDataset2()
{
DefaultXYDataset result = new DefaultXYDataset();
XYSeries series1 = new XYSeries("Words");
series1.add(0.3, 0);
series1.add(0.5, 1);
series1.add(0.6, 2);
series1.add(0.3, 3);
series1.add(0.2, 4);
result.addSeries(getTitle(), series1.toArray());
return result;
}
private JFreeChart createChart2(XYDataset dataset, String title)
{
JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
"Words",
"Activation",
dataset, // data
PlotOrientation.HORIZONTAL,
true, // include legend
true,
false);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setForegroundAlpha(0.5f);
String[] grade = new String[5];
grade[0] = "Temp 0";
grade[1] = "Temp 1";
grade[2] = "Temp 2";
grade[3] = "Temp 3";
grade[4] = "Temp 4";
SymbolAxis rangeAxis = new SymbolAxis("Words", grade);
rangeAxis.setTickUnit(new NumberTickUnit(1));
rangeAxis.setRange(0,grade.length);
plot.setRangeAxis(rangeAxis);
return chart;
}
Using:
plot.setDomainAxis(rangeAxis);
solves my problem.
Thanks to trashgod for the help.