Issues with jqPlot / Primefaces extension and Date values

so that's the thing. I have a lot of surviving "snapshots" containing java.sql.Timestamp and (for simplicity) int as data.

I have a JSF page containing 3.4.1 price lists <p:lineChart>

and behind this ManagedBean which contains a model for a diagram.

Let's say I then select a time range and extract all the images in between that range. and populate the data model for the chart with all timestamps (x-axis) and all integers (y-axis).

So what I do during check-in:

data = new HashMap<Object, Number>();        
List<Snapshot> allSnapshots = persistenceService.getAllSnapshots();
for(int i = 0; i < allSnapshots.size(); i++) {
    Snapshot s = allSnapshots.get(i);
    data.put(new Date(s.getTimestamp().getTime()), s.getData());
}
chartModel.getSeries().get(0).setData(data);

      

(Note: in the example code, I'm just fetching all the snapshots as I quickly only created a hundred or so).

I set up the diagram like this:

<p:lineChart id="chart" value="#{backingBean.chartModel}" xaxisAngle="-90">
   <f:convertDateTime pattern="HH:mm:ss"/>
</p:lineChart>

      

It works fine, but when the model contains one hundred data points, xaxis is just overflowing with all the marks.

What I did then was to use the primefaces option to use the jqplot extension function. So I just add extender="extend"

as an attribute for the chart, where extend

is the following js function:

function extend() {
      this.cfg.axes = {
          xaxis: {
              renderer: $.jqplot.DateAxisRenderer,
              rendererOptions: { tickRenderer: $.jqplot.CanvasAxisTickRenderer },
              tickOptions: {
                  showGridline: true,
                  formatString: '%H:%M',
                  angle: -90                        
             }         
         }
     }
}

      

This is the current version. After hours of reading, trial and error, I still cannot get it right, as the following things are simply not right:

  • Label characters are never displayed because the date is never converted. For now, this is simply ignored and the formatString itself is displayed ...
  • Additional label marks are created to the left and right of the actual data, I don't want that.
  • When I provide autoscale: true

    as an option for the jqplot expander, I would expect the spacing between the labels to be normal. But it happens that the distance is cold, but the original date labels turn into a prime number, starting from 0 to the amount of available data ..!?

I'm a little tired of dealing with this ..... maybe I'm doing something fundamentally wrong. Otherwise, I have no idea why it is so difficult.

Thanks for any advice!

Greetings

Chris


EDIT:

Well thanks to perissf, I checked this out on stackoverflow.

With the proposed extender I get the following output: http://www.abload.de/img/clipboard01y6sgj.png

(sorry I can't post the image directly due to new custom restrictions: - /)

As you can see, the labels are marked correctly like HH: MM, which is very nice. But, as you can also see, another rather strange problem arises:

This time range of images

  • Start time: 2013-01-28 13: 01: 25.415
  • End time: 2013-01-28 13: 14: 32.145

I collected them as UTC time stamps using System.currentTimeMillis () while the JVM is set to UTC in the config on the stack.

As you noticed, the data on the chart is shifted by one hour, it starts at 14:01, which looks like the values ​​were automatically converted to my current timezone, which is UTC + 1. But the leftmost xaxis tick is placed at about original UTC at 13:00.

I am collecting UTC timestamps as I do not know what actual time zone the application will be in, but I would like to display the "translated" time value. So auto-switching to my timezone is a nice feature, but xaxis scaling isn't really nice and weird.

Any suggestions how I get rid of this?

Greetings

Chris


EDIT2:

Okay while debugging the rendered page with Firebug, I came across jqplot internal variables in the plot object that appear to hold the minimum and maximum values ​​for xaxis. Min is set to the original UTC minimum, which is around 13:00, and max is the UTC + 1 shifted value around 14:15.

Somehow the minimum value doesn't shift according to the automatic timezone settings.

All other values, i.e. dataBounds, the data itself, etc., carry over well for one hour.

I have opened an issue in Error Tracker for bitbucket jqplot

We'll see.

Bye

Chris

+3


source to share


2 answers


i finally debugged the jqplot renderer and found some lines of code that are causing this behavior.

For anyone you're interested in, please find a fix in the comment section here: Bitbucket Bug Tracker



Thanks for any help

0


source


I'm very interested in this fix, but the problems in BitBucket are in a limited area, so I can't access it. So I tried to fix this AxisDateRenderer and luckily I did :)

Thus, the Primefaces diagram (6.0) uses the old version of the JQPlot library. A bug in this version sets a minimum date boundary that is not the first value exactly, but a time older according to the timezone of the user's browser locale. For example, if the first value is at 12:00 and your GMT is GMT + 1, then the minimum minimum date size will be 11:00 instead of 12:00!

minVale

The next line (in the createTicks function) is to replace the bed (note the code is below)

ad = ad.getTime() + ad.getUtcOffset();

      

On the next line:



ad = Math.floor((ad.getTime() - ad.getUtcOffset())/r) * r + ad.getUtcOffset();

      

Unminified replacement string:

min = min.getTime()  + min.getUtcOffset();

      

FROM

 min = Math.floor((min.getTime() - min.getUtcOffset())/tempti) * tempti + min.getUtcOffset();

      

Please note that I tried to update chart.js from Primefaces to an earlier version, but the chart no longer works. I will wait for the next Primefaces update, hoping a newer version will be used. I also don't know which version of JQPlot is used in Primefaces 6.0

0


source







All Articles