I need to know what the code is to get into a chart’s y-axis upper and lower bound property. We need to change the upper and lower bounds of a chart to values we have stored in the database while the app is running. I found the code to access the upper and lower bounds of an easy chart, but was unable to alter it successfully to apply to a standard chart.
First of all, if you have a fixed set of axes, you can simply create them and switch the datasets to display against different axes via the setDatasetYAxis function.
Now, if that doesn’t work, you can do this with some scripting.
The following code will alter the upper and lower bound on a Y axis called “Default Y Axis”.
[code]chart = event.source.parent.getComponent(“Chart”)
axes = chart.getYAxes()
axis = axes.get(“Default Y Axis”)
#Tells the chart to re-fresh itself
Hope this helps,
Here is a demo FPMI window demonstrating a variation to Carl’s code for adjusting an Easy Chart’s axis limits (i.e., bounds).
Thanks so much. That worked beautifully. I didn’t want to use the setDataSetYAxis function because I have over 100 possible lower and upperbounds and didn’t want to create that many axes.
Can’t blame you! +1 for scripting magic.
Ok, now that I got the chart to use the upper and lower bounds to scale the chart, is there anyway to force the chart to display these values as their min and max? As it stands now the chart only displays the even values (0, 2500, 5000, 1500, 57500, etc) and does not show these min and max points from the database. I have a workaround in place of just showing these values at the top and bottom of the chart (see picture), but would like to know if I can incorporate it otherwise. Thanks!
In order to get FPMI to show the exact lower and upper bounds values as part of the chart you would need to manipulate the Tick and Grid Units of the chart. Even so, it would be quite complicated to accomplish what you want.
Practically, you’re probably already doing the best thing now. The only suggestion I can make is to move your limit values so they line up with the upper and lower edges of the chart. This may or may not work because of the dynamic formatting of the chart but it might work if the chart layout is fairly consistent.
Another suggestion is to round your limits up or down so that they fall on “even” values.
Yeah, Bob is right. Its technically possible, but trust me, its so not worth it - it involves getting deep into the underlying JFreeChart code, and it will be really tough. You could just put labels over the chart at the top and bottom of the Y axis…
I’m trying to use the code of Carl.Goud but I get the message object has no attribute ‘getYAxes’. I think it may be because I am using a Easy Chart . Does anyone know what would be the equivalent attribute?
What would be the attribute to hide certain Y axis? (I’m lookin for something similar to “event.source.parent.getComponent(“Chart”).getChart().getXYPlot().getRangeAxis().setVisible(0)”
Thanks in advance
Altering the y-axes on the easy chart is much easier.
Simply manipulate the easy chart’s “yAxes” dataset!
Thank you Carl, but really I have not found a way to solve my situation changing the axes Dataset.
I have a Easychart limited only to 10 SQL Tags historian pens, each of these pens is selected dynamically by ten dropdown list. All pens have (initially) only one Y Axe with autorange.
In some situations, one of the pens can have very small variations in value so that it appears to be a straight line. For such cases need to shift the “y” axis without affecting the auto range of others, it is not necessary to see the Y axe (although I would like to superimpose a different color). Tools such as zoom or different plots not solve my need in this case.
I’m trying to solve this problem as follows.
- I have a dropdown list to select the tag that I want to change the range
- Two numeric text field (for lower bound and upper bound)
- Two check box (one to hide or show the axis and another to assign the axis autoranging pen)
- A button that when pressed run the script to bind the pen to another axis with the indicated bounds.
My idea is to have 11 axes, one for autoranging and 10 so that in the worst case each pen has its axis, this obviously made by the script of the button. I also need that when changing the pen, has assign the autorange axe.
If you’re already manipulating the pens dataset, you should be able manipulate the yAxes datasets with ease.
You could add/remove axes as you wish, and set their ranges or toggle the autorange bit as well.