Line chart's X-Axis labels are not showing completely
-
- Posts: 23
- Joined: Mon Sep 18, 2006 10:08 am
- Location: Mumbai, India
- Contact:
Line chart's X-Axis labels are not showing completely
hi,
i have one line chart having morethan 7 X-axis labels. when i execute my code the chart is displaying well but the X-axis labels are not displaying completely. those are displaying as following sequence.
24/3.. 25/3.. 26/3.. 27/3.. 28/3.. 30/3.. 31/3..
but i have to get the full dates as the following sequence.
24/3/2006 25/3/2006 26/3/2006 27/3/2006 28/3/2006 30/3/2006 31/3/2006
could you please anyone give me the suggestion.
regards,
Sumant
i have one line chart having morethan 7 X-axis labels. when i execute my code the chart is displaying well but the X-axis labels are not displaying completely. those are displaying as following sequence.
24/3.. 25/3.. 26/3.. 27/3.. 28/3.. 30/3.. 31/3..
but i have to get the full dates as the following sequence.
24/3/2006 25/3/2006 26/3/2006 27/3/2006 28/3/2006 30/3/2006 31/3/2006
could you please anyone give me the suggestion.
regards,
Sumant
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
It looks like you are using a CategoryAxis to display a value scale. It would be better to use a DateAxis (with an XYPlot), since it handles the tick spacing automatically.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 23
- Joined: Mon Sep 18, 2006 10:08 am
- Location: Mumbai, India
- Contact:
Hi Dave Gilbert
Thanks Dave Gilbert,
Can you please tell me the how to use them in our.
i hope you will give the suggestion
thanks,
Sumant
Can you please tell me the how to use them in our.
i hope you will give the suggestion
thanks,
Sumant
-
- Posts: 23
- Joined: Mon Sep 18, 2006 10:08 am
- Location: Mumbai, India
- Contact:
Code: Select all
public class WeeklyLineChart extends ApplicationFrame {
private float energyUsage;
private String xAxisLabelsString;
private float yAxisMaxValue = 0;
private double transactionHistory;
private String Y_AXIS_TITLE = "Percentage";
public WeeklyLineChart(final String title) {
super(title);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart, false);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
private CategoryDataset createDataset() {
String readDateTime = null;
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
xAxisLabelsString = new String();
xAxisLabelsString = "23/3/2006";
transactionHistory = 23.3;
System.out.println("the XBefore -AXIS Labels are "+xAxisLabelsString);
dataset.addValue(transactionHistory,"Time", xAxisLabelsString);
dataset.addValue(43.2,"Time", "24/3/2006");
dataset.addValue(89.2,"Time", "25/3/2006");
dataset.addValue(11.2,"Time", "26/3/2006");
dataset.addValue(32,"Time", "27/3/2006");
dataset.addValue(5,"Time", "28/3/2006");
dataset.addValue(67,"Time", "30/3/2006");
dataset.addValue(27,"Time", "31/3/2006");
// dataset.addValue(17,"Time", "29/3/2006");
// dataset.addValue(125,"Time", "20/3/2006");
// dataset.addValue(24,"","22/3/2006");
return dataset;
}
private JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createLineChart(
"Line Chart Demo 6", // chart title
"", // x axis label
"Percentage", // y axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
chart.getTitle().setFont(new Font("Verdana Helvetica Arial", Font.PLAIN, 14));
// chart.setNotify(false);
//chart.removeLegend();
chart.setLegend(null);
// final XYPlot plot = chart.getXYPlot();
// plot.setBackgroundPaint(Color.lightGray);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setDomainGridlinePaint(Color.blue.darker());
plot.setRangeGridlinePaint(Color.white);
plot.setDrawSharedDomainAxis(false);
CategoryAxis domainAxis = plot.getDomainAxis();
// domainAxis.setLabel("Hello");
// domainAxis.setCategoryLabelPositionOffset(32);
domainAxis.setLabelFont(new Font("Verdana Helvetica Arial", Font.BOLD, 14));
domainAxis.setTickLabelFont(new Font("Verdana Helvetica Arial", Font.PLAIN, 10));
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
domainAxis.setCategoryMargin(00);
domainAxis.setLowerMargin(00);
domainAxis.setUpperMargin(00);
domainAxis.setTickMarksVisible(true);
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setDrawLines(true);
renderer.setSeriesStroke(0, new BasicStroke(1.0f));
Paint p1 = new GradientPaint(
0.0f, 0.0f, new Color(0x22, 0x22, 0xFF).darker(), 0.0f, 0.0f, new Color(0x88, 0x88, 0xFF)
);
renderer.setPaint(p1,true);
plot.setRenderer(renderer);
return chart;
}
public static void main(final String[] args) {
final WeeklyLineChart demo = new WeeklyLineChart("Line Chart");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
-
- Posts: 23
- Joined: Mon Sep 18, 2006 10:08 am
- Location: Mumbai, India
- Contact: