how to display LineChart X axis lables vertically
-
- Posts: 25
- Joined: Mon Oct 08, 2007 7:16 am
how to display LineChart X axis lables vertically
I have generated a line graph and a scatter plot......i want to display the X axis labels vertically(horizontal by default) as the lables to be displayed are lengthy.....can some one tell me how to do this
thanks
mahesh
mahesh
-
- Posts: 25
- Joined: Mon Oct 08, 2007 7:16 am
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Code: Select all
axis.setCategoryLabelPositions(CategoryLabelPositions.UP 90);
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
-
- Posts: 25
- Joined: Mon Oct 08, 2007 7:16 am
thanx for quick reply.....but i am nowhere using CategoryAxis.....
here is my code............
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
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.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.ChartUtilities;
import java.io.File;
import java.sql.Timestamp;
import java.text.*;
public class GenerateLineChart {
Timestamp startTime = null;
Timestamp endTime = null;
String portFolio = null;
String application = null;
float[] xPoints = null;
String[] yPoints = null;
String strStartTime = null;
String strEndTime = null;
public GenerateLineChart(String portFolio,String application,float[] xPoints,String[] yPoints,Timestamp startTime,Timestamp endTime) {
super("");
this.portFolio = portFolio;
this.startTime = startTime;
this.endTime = endTime;
this.application = application;
this.xPoints = xPoints;
this.yPoints = yPoints;
strStartTime = convertToString(startTime);
strEndTime = convertToString(endTime);
final CategoryDataset dataset = createDataset(xPoints,yPoints);
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
// To save the JFreeChart as JPEG File at the specified location
try{
ChartUtilities.saveChartAsJPEG(new File("D:\\JFreeChartExamples\\"+"LineChart.jpg"), 0.25f, chart, 650, 425);
}catch(Exception e){e.printStackTrace();}
}
private CategoryDataset createDataset(float[] xPoints,String[] yPoints) {
final String imageLable = "Availability Graph";
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i=0;((i<xPoints.length) && (i<yPoints.length));i++){
if(Float.isNaN(xPoints)){
dataset.addValue(null, imageLable, yPoints);
}else{
dataset.addValue(xPoints, imageLable, yPoints);
}
}
return dataset;
}
private JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createLineChart(
"Availability Chart", // chart title
"Time", // domain axis label
"Availability %", // 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);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setSeriesStroke(
1, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {10.0f, 6.0f}, 0.0f
)
);
return chart;
}
}
here is my code............
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
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.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.ChartUtilities;
import java.io.File;
import java.sql.Timestamp;
import java.text.*;
public class GenerateLineChart {
Timestamp startTime = null;
Timestamp endTime = null;
String portFolio = null;
String application = null;
float[] xPoints = null;
String[] yPoints = null;
String strStartTime = null;
String strEndTime = null;
public GenerateLineChart(String portFolio,String application,float[] xPoints,String[] yPoints,Timestamp startTime,Timestamp endTime) {
super("");
this.portFolio = portFolio;
this.startTime = startTime;
this.endTime = endTime;
this.application = application;
this.xPoints = xPoints;
this.yPoints = yPoints;
strStartTime = convertToString(startTime);
strEndTime = convertToString(endTime);
final CategoryDataset dataset = createDataset(xPoints,yPoints);
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
// To save the JFreeChart as JPEG File at the specified location
try{
ChartUtilities.saveChartAsJPEG(new File("D:\\JFreeChartExamples\\"+"LineChart.jpg"), 0.25f, chart, 650, 425);
}catch(Exception e){e.printStackTrace();}
}
private CategoryDataset createDataset(float[] xPoints,String[] yPoints) {
final String imageLable = "Availability Graph";
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i=0;((i<xPoints.length) && (i<yPoints.length));i++){
if(Float.isNaN(xPoints)){
dataset.addValue(null, imageLable, yPoints);
}else{
dataset.addValue(xPoints, imageLable, yPoints);
}
}
return dataset;
}
private JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createLineChart(
"Availability Chart", // chart title
"Time", // domain axis label
"Availability %", // 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);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setSeriesStroke(
1, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {10.0f, 6.0f}, 0.0f
)
);
return chart;
}
}
thanks
mahesh
mahesh
-
- Posts: 25
- Joined: Mon Oct 08, 2007 7:16 am