Line chart's X-Axis labels are not showing completely

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
skkuchipudi
Posts: 23
Joined: Mon Sep 18, 2006 10:08 am
Location: Mumbai, India
Contact:

Line chart's X-Axis labels are not showing completely

Post by skkuchipudi » Mon Oct 16, 2006 5:30 pm

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

user1
Posts: 7
Joined: Thu Oct 12, 2006 8:33 am

Post by user1 » Mon Oct 16, 2006 8:31 pm

i have the same problem as yours, when i drop or delete the domain label it displayed well, but its not a solution...but you can place the domain label somewhere else maybe at the right.
i want to display the domain label at the left in the corner but i couldn't do so. :(

jusepi
Posts: 16
Joined: Tue May 09, 2006 1:18 pm
Location: USA

Post by jusepi » Tue Oct 17, 2006 2:01 am

maybe you could try having the labels on an angle instead of horizontal to allow for more room for the text..

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 » Tue Oct 17, 2006 10:19 am

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

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

skkuchipudi
Posts: 23
Joined: Mon Sep 18, 2006 10:08 am
Location: Mumbai, India
Contact:

Hi Dave Gilbert

Post by skkuchipudi » Tue Oct 17, 2006 2:07 pm

Thanks Dave Gilbert,


Can you please tell me the how to use them in our.
i hope you will give the suggestion


thanks,
Sumant

adnanak
Posts: 5
Joined: Sat Oct 14, 2006 9:09 am

Post by adnanak » Thu Oct 19, 2006 10:42 am

Dear Can u send me the sample line graph code bcoz i am facing problem to display simple line graph. Thnx for considering.

skkuchipudi
Posts: 23
Joined: Mon Sep 18, 2006 10:08 am
Location: Mumbai, India
Contact:

Post by skkuchipudi » Thu Oct 19, 2006 11:25 am

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

    }

}

user1
Posts: 7
Joined: Thu Oct 12, 2006 8:33 am

Post by user1 » Sun Oct 22, 2006 4:04 pm

hi skkuchipudi.

did you find solution for not displaying the X-axis labels completly? please answer.

thanks.

skkuchipudi
Posts: 23
Joined: Mon Sep 18, 2006 10:08 am
Location: Mumbai, India
Contact:

Post by skkuchipudi » Thu Oct 26, 2006 4:51 pm

no i did not get the result.

Locked