how to display LineChart X axis lables vertically

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mahesh_burgu
Posts: 25
Joined: Mon Oct 08, 2007 7:16 am

how to display LineChart X axis lables vertically

Post by mahesh_burgu » Wed Oct 31, 2007 2:16 am

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_burgu
Posts: 25
Joined: Mon Oct 08, 2007 7:16 am

Post by mahesh_burgu » Wed Oct 31, 2007 2:30 pm

is there any one to help me
thanks
mahesh

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Oct 31, 2007 3:06 pm

Code: Select all

axis.setCategoryLabelPositions(CategoryLabelPositions.UP 90);
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

mahesh_burgu
Posts: 25
Joined: Mon Oct 08, 2007 7:16 am

Post by mahesh_burgu » Wed Oct 31, 2007 4:27 pm

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;
}


}
thanks
mahesh

mahesh_burgu
Posts: 25
Joined: Mon Oct 08, 2007 7:16 am

Post by mahesh_burgu » Wed Oct 31, 2007 4:40 pm

i got the solution.......thanx david


final ValueAxis rangeAxis = ((CategoryPlot) plot).getRangeAxis();
CategoryAxis domainAxis = ((CategoryPlot) plot).getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
thanks
mahesh

Locked