log-log or semi-log graph

1,735 views
Skip to first unread message

Jack Lewis

unread,
Jan 29, 2013, 10:01:12 AM1/29/13
to jsxg...@googlegroups.com
How do I create a log-log or semi-log graph?

michael

unread,
Feb 1, 2013, 3:23:16 AM2/1/13
to jsxg...@googlegroups.com
Hi,

I guess the axes are the problem. In the next version the tick element used to display the markers on axes will be improved such that you can provide a function that transforms the value of the tick. I put up an example:


Another thing to be aware of is the infobox that displays the coordinates when you hover over a point. You can define the text that is to be displayed yourself, see the example above how to do this.

The graph itself can be generated like any other plot except you need some functions to transform the input and maybe the output.


Michael

Jack Lewis

unread,
Feb 1, 2013, 4:27:54 PM2/1/13
to jsxg...@googlegroups.com
Michael,

This is exactly what I need. I have made log-log and semi-log plots using html5 canvas and javascript, but I would prefer to use jxgraph for my current project. When I copy the code from the jsxgraph you sent and use it with your standard jsxgraph javascripts all works except the axis is not scaled. So I understand that you have to make changes in your code. What you have done is a big help. What's your time frame?

michael

unread,
Feb 1, 2013, 4:33:37 PM2/1/13
to jsxg...@googlegroups.com
The changes will be included in our next release. We don't have a new release planned yet but you can always try our nightly builds that are generated every evening at 10pm CET, e.g. this one from ~30 minutes ago:

brian...@gmail.com

unread,
Apr 12, 2013, 6:33:51 PM4/12/13
to jsxg...@googlegroups.com
Hi,
I am looking to plot on log scale as well. Have you released a new version with the above feature yet?  If not, is there a somewhat stable nightly build that has this feature?

Thanks,
Brian

michael

unread,
Apr 13, 2013, 2:05:33 AM4/13/13
to jsxg...@googlegroups.com, brian...@gmail.com
We are currently preparing the next release that contains this feature. Except some arc related intersection problems last week's snapshots are stable. Before using one of these versions, make sure to take a look at our notes for the release candidate:


There were a few changes that might affect existing examples.


Michael

brian...@gmail.com

unread,
Apr 14, 2013, 2:40:51 PM4/14/13
to jsxg...@googlegroups.com, brian...@gmail.com
Thanks, I used your example above against both the release candidate and against the build on 2013-02-01.2101 and I am seeing different behaviour between the two versions.  Does the example still reflect the proper way to do this?

Thanks,
Brian
build_2013-02-01.2101.html
release_candidate.html

michael

unread,
Apr 15, 2013, 2:45:21 AM4/15/13
to jsxg...@googlegroups.com, brian...@gmail.com
You're right, we moved the generateLabelValue() function from the parents array to the attributes:

    t = board.create('ticks', [x, 1], {
        // yes, show the labels
        drawLabels: true,
        // yes, show the tick marker at zero (or, in this case: 1)
        drawZero: true,
        generateLabelValue: function (tick) {
       // get the first defining point of the axis
       var p1 = this.line.point1;
       // this works for the x-axis, for the y-axis you'll have to use usrCoords[2] (usrCoords[0] is the z-coordinate).
       return Math.pow(10, tick.usrCoords[1] - p1.coords.usrCoords[1]);
   }
    });

The generateLabelValue() property in the third parameter of this board.create() call was previously in the array (the second parameter). The scrambled navigation bar is already fixed in current HEAD.


Michael

brian...@gmail.com

unread,
Apr 15, 2013, 11:29:27 AM4/15/13
to jsxg...@googlegroups.com, brian...@gmail.com
Great. works for me. thanks!

brian...@gmail.com

unread,
Apr 15, 2013, 4:28:17 PM4/15/13
to jsxg...@googlegroups.com, brian...@gmail.com
One thing I noticed is that if you move toward the left in the graph (lower magnitide x values), you don't get the scientific notation like you do for larger values.  Is there anyway to get scientific notation?

E.G.
0.0000001 displayed as 0
1000 displayed as 1.00e+3
Screen Shot 2013-04-15 at 13.26.51.png

Michael

unread,
Apr 17, 2013, 4:15:46 AM4/17/13
to jsxg...@googlegroups.com
Thanks, this bug is fixed now. I built a new version with this fix included:



Michael

Murray

unread,
Oct 11, 2014, 3:14:54 AM10/11/14
to jsxg...@googlegroups.com
Hi Michael

generateLabelValue does not appear to be working any more.

In this example, the x-axis has ordinary labels, not powers off 10:


What is the correct syntax for logarithmic axis labels?

Thanks
Murray

Alfred Wassermann

unread,
Oct 23, 2014, 7:36:57 AM10/23/14
to jsxg...@googlegroups.com
Dear Murray,
sorry for the delay, but I finally found the problem. More than a year ago, the tick method generateLabelValue() has been replaced by generateLabelText(). But the corresponding attribute haswas not replaced. I marked generateLabelValue now as deprecated.
In the next version the correct code for a semi-log graph is:
    t = board.create('ticks', [x, 1], {
       
// yes, show the labels
        drawLabels
: true,
       
// yes, show the tick marker at zero (or, in this case: 1)
        drawZero
: true,

       
/*

        generateLabelValue: function (tick) {
            // get the first defining point of the axis
            var p1 = this.line.point1;

            // this works for the x-axis, for the y-axis you'll have to use usrCoords[2] (usrCoords[0] is the z-coordinate).
            return Math.pow(10, tick.usrCoords[1] - p1.coords.usrCoords[1]);
        },
        */

        generateLabelText
: function (tick, zero) {

           
// this works for the x-axis, for the y-axis you'll have to use usrCoords[2] (usrCoords[0] is the z-coordinate).

           
return (Math.pow(10, Math.round(tick.usrCoords[1] - zero.usrCoords[1]))).toString();
       
}
   
});

A work around for the present version 0.99.1 is:
    t = board.create('ticks', [x, 1], {...});

    t
.generateLabelText = function (tick, zero) {

           
// this works for the x-axis, for the y-axis you'll have to use usrCoords[2] (usrCoords[0] is the z-coordinate).

           
return (Math.pow(10, Math.round(tick.usrCoords[1] - zero.usrCoords[1]))).toString();
       
};
    board
.update();


Best wishes,
Alfred

Murray

unread,
Oct 25, 2014, 11:10:36 PM10/25/14
to jsxg...@googlegroups.com
Thank you Alfred!

That works fine now.

Regards
Murray
Reply all
Reply to author
Forward
0 new messages