Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having trouble inverting the left-side y-axis on my line chart, which is generated by jQuery/JQplot scripts.

I have two separate JavaScript arrays with identical x values (dates) in both arrays. My chart has a y-axis and a y2axis. I would like to invert the y-axis so that the lower values start from the top down, instead of bottom up.

This is a snippet of my code:

C#
var rsWell2 =['3/30/2000', 74.38], ['1/26/2001', 62.23], ['2/15/2002', 63.67...
var rsWell4 = ['3/30/2000', -53.38], ['1/26/2001', -41.23], ['2/15/2002', -42.67]...


var plot1 = $.jqplot('chart', [rsWell2, rsWell4], { ...


xaxis:{
                        tickOptions:{
                            fontSize: '9pt',
                            angle:-60,
                            formatString:'%D'
                        },
                        tickRenderer:$.jqplot.CanvasAxisTickRenderer,

                        label: 'Date',
                        renderer:$.jqplot.DateAxisRenderer


                    },



yaxis:{

                       label: 'Depth to Water Level (ft below land)',
                       labelRenderer: $.jqplot.CanvasAxisLabelRenderer,

                       rendererOptions:{

                           tickRenderer:$.jqplot.CanvasAxisTickRenderer},
                       tickOptions:{
                           fontSize: ...
                           formatString: ...
                           alignTicks: true

                           //min: Math.max.apply(null, rsWell2),
                           //max: Math.min.apply(null, rsWell2)

                       }

y2axis:{
                        
                            tickOptions:{...}
                         
                        }

Because my array values are always changing, I cannot specify a min and max value. I have tried many different ways and am now very frustrated! How can I accomplish this? Any help is greatly appreciated.

Liz
Posted
Comments
Sergey Alexandrovich Kryukov 10-Jul-15 23:53pm    
How about y -> ymax - y?
—SA
Liz Heal 13-Jul-15 10:07am    
This is what I currently have:

var rsWell6 = rsWell5.slice(1);
var minVal = Math.min.apply(null, rsWell6);
var maxVal = Math.max.apply(null, rsWell6);

//need to fix math here

var minVal1 = Math.floor(minVal) - 10;
var maxVal1 = Math.round(maxVal) + 10;

more code...

rendererOptions:{
alignTicks: true,
min: maxVal1,
max: minVal1,

...

This does work. However, the tick scaling does not line up correctly to the other y-axis. Any thoughts?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900