Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9131937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:13:32+00:00 2026-06-17T08:13:32+00:00

I am using PrimeFaces 3.4.1 to plot time chart (Date on x-axis, int value

  • 0

I am using PrimeFaces 3.4.1 to plot time chart (Date on x-axis, int value on y-axis).

At the moment I have something like that:

xhtml:

<p:lineChart id="timeChart" value="#{myGraphBean.model}" legendPosition="e" title="Time Chart" minY="0" maxY="25" style="height:300px"/>

Java bean:

private final static int MAX_VALUE = 20;
private final static int NUMBER_OF_POINTS = 20;
private final static DateFormat dateFormat = new SimpleDateFormat("dd-MM-yy");

private void createLinearModel() {
    model = new CartesianChartModel();
    Calendar day = Calendar.getInstance();
    day.set(Calendar.HOUR_OF_DAY, 0);
    day.set(Calendar.MINUTE, 0);
    day.set(Calendar.SECOND, 0);
    day.set(Calendar.MILLISECOND, 0);
    LineChartSeries series = new LineChartSeries();
    series.setLabel("My series");
    for (int i = 0; i < NUMBER_OF_POINTS; i++) {
        series.set(dateFormat.format(day.getTime()), getRandomValue());
        day.add(Calendar.DAY_OF_MONTH, 1);
    }
    model.addSeries(series);
}

private int getRandomValue() {
    return rand.nextInt(MAX_VALUE);
}

So my bean just creates some random int value for each day. (My application produces actual data points, this is just a dummy example)

In my application, I am generating data over a long time, for example 6 months. With the way I am doing things now, I get horrible graphs like that:

Bad graph

What I would like to do:

I’d like to be able to keep my data point but only display a tick, let’s say every month.

I have tried to change the tick on the x-axis following a few other posts (ex1, ex2) but I couldn’t get it work.

Using the primefaces extender, I tried to use things like tickInterval: '1 month', setting the min attributes but nothing worked. In most of the case it would just break the graph

Questions:

  1. In the jqPlot doc, it says “Note, although jqPlot will parse most any human readable date, it is safest to use javascript time stamps when possible. Also, it is best to specify a date and time and not just a date alone. This is due to inconsistent browser handling of local time vs. UTC with bare dates.”
    In my graph bean, shall I populate the series using a formatted date (String) following the javascript time stamp (“yyyy-MM-dd h:mma”) or using a java.util.Date directly?

  2. How can I change the x-axis tick (for let’s say 1 month), having a marker only every month, but still have the graph going through all the day points (i.e. I don’t want to average my the points over the month)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:13:33+00:00Added an answer on June 17, 2026 at 8:13 am

    In Java, fill your LineChartSeries objects with times in milliseconds using Date#getTime().

    On the facelets side, download from jqPlot site and import the following jqPlot plugins:

    <h:outputScript name="Javascript/jqplot.canvasAxisTickRenderer.js" />
    <h:outputScript name="Javascript/jqplot.canvasAxisTickRenderer.min.js" />
    <h:outputScript name="Javascript/jqplot.dateAxisRenderer.js" />
    <h:outputScript name="Javascript/jqplot.dateAxisRenderer.min.js" />
    

    And use this js extender for p:lineChart component:

    function chartExtender() {
        this.cfg.axes = {
            xaxis : {
                renderer : $.jqplot.DateAxisRenderer, 
                rendererOptions : {
                    tickRenderer:$.jqplot.CanvasAxisTickRenderer
                },
                tickOptions : { 
                    fontSize:'10pt',
                    fontFamily:'Tahoma', 
                    angle:-40
                }
            },
            yaxis : {
                rendererOptions : {
                    tickRenderer:$.jqplot.CanvasAxisTickRenderer
                },
                tickOptions: {
                    fontSize:'10pt', 
                    fontFamily:'Tahoma', 
                    angle:30
                }
            }               
        };
        this.cfg.axes.xaxis.ticks = this.cfg.categories;
    }
    

    Useful links:

    http://forum.primefaces.org/viewtopic.php?f=3&t=25289#p79916

    http://forum.primefaces.org/viewtopic.php?f=3&t=23891&p=78637#p78637

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PrimeFaces checkbox on a JSF page that I'd like to check/uncheck
I'm using Primefaces 3.3.1 and have a <p:selectOneMenu> where I'm selecting a new value.
I'm using Primefaces 3.3.1 and have question. I have p:commandButton inside p:column of p:dataTable.
I am using primefaces photoCam component exactly as explained in https://www.primefaces.org/showcase/ui/multimedia/photoCam.xhtml . unfortunately, unlike
I'm using PrimeFaces 3.4.2 and I have to use <p:dataTable> . I want fixe
I'm using Primefaces p:inplace such that when some text is clicked, it's replaced with
I'm using primefaces and jstl to loop a datatable.I have a List in backing
I am using primefaces 3.2 and I have used escape=false for the outputText to
I am using primefaces for not so long and Ive found that I cant
I'm using Primefaces 3.0.RC1 and on a form I have a <p:fileUpload mode=advanced auto=true>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.