make label in type line (x line) is vertical in jfreechart

Saturday, July 5, 2014

I have created an application that show my data in jtable into a jfreechart. The version of my jfreechart is a line chart. The screenshot is like this :


http://ift.tt/1jSV9IH



  1. How to make the label in line of type is vertical, so it will look neat or orderly

  2. How to make a label of value in meetings axis values ​​and axis type


This is my code



public class LineChartDemo1 extends ApplicationFrame {

/**
* Creates a new demo.
*
* @param title the frame title.
*/
List<ReportChart> theDatas;

public LineChartDemo1(final String title, List<ReportChart> chartData) {
super(title);

this.theDatas = chartData;
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);

Main_Menu.presentase.removeAll(); // My form
Main_Menu.presentase.setLayout(new java.awt.BorderLayout()); // My form
Main_Menu.presentase.add(chartPanel); // My form
}

/**
* Creates a sample dataset.
*
* @return The dataset.
*/
private CategoryDataset createDataset() {


final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

String algorithm1 = "Levensthein";

String algoritma2 = "SmithWaterman";

for (int i = 0; i < Main_Menu.jTable3.getRowCount(); i++) {

Object fileName = Main_Menu.jTable3.getValueAt(i, 1);
String fileNameToString = namaFile.toString();

Object nilaiLevensthein = Main_Menu.jTable3.getValueAt(i, 2);
double value1 = Double.parseDouble(nilaiLevensthein.toString());

Object nilaiSmithWaterman = Main_Menu.jTable3.getValueAt(i, 3);
double value2 = Double.parseDouble(nilaiSmithWaterman.toString());

dataset.addValue(value1, algoritma1, fileNameToString);
dataset.addValue(value2, algoritma2, fileNameToString);

}

return dataset;

}

private JFreeChart createChart(final CategoryDataset dataset) {

Object namaFile = Main_Menu.jTable3.getValueAt(0, 0);
String namaFileKeString = namaFile.toString();

// create the chart...
final JFreeChart chart = ChartFactory.createLineChart(
"Persentase Kemiripan", // chart title
"File-file Pembanding", // domain axis label
namaFileKeString, // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);

chart.setBackgroundPaint(Color.white);

final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);

// customise the range axis...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);

final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
//renderer.setDrawShapes(true);

renderer.setSeriesStroke(
0, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{10.0f, 6.0f}, 0.0f
)
);
renderer.setSeriesStroke(
1, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{6.0f, 6.0f}, 0.0f
)
);
renderer.setSeriesStroke(
2, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[]{2.0f, 6.0f}, 0.0f
)
);


return chart;
}

}


For the help, thank you so much.







http://ift.tt/1jSVcnS