Control decimal places on Y-axis of chart

I have two charts that are placed one above the other. My problem is the Y-axis values sometimes have 2 decimal, 3 decimal, or 4 decimal places and the two charts adjust to being different widths. Is there a way to always have the Y-axis use 4 decimal places?

Attached is a picture of the problem.

On a side note does the chart component have the ability to draw a different color between two points if a condition is met? In the second picture attached the chart has a yellow line if the time between points is over and hour and a red line if the time between points is over 2 hours.



Let me answer your second question first (about the conditional line colors): Sorry, no.

Ok, now your first question. The official answer is also no. The unofficial and unsupported (as in no guaranteed backwards compatability) answer is: yes, with scripting.

Something like this:

from org.jfree.chart.axis import NumberTickUnit from java.text import DecimalFormat chart = event.source.parent.getComponent("Chart") axis= chart.getChart().getPlot().getRangeAxis() axis.setTickUnit(NumberTickUnit(.005, DecimalFormat("#.000")))

The trick would be to know when that code needs to get executed, as its effect will be clobbered every time the chart re-creates itself due to a data change.

Hope this helps,

I am receiving this error when I trying using the code:

Traceback (innermost last):
File “event:propertyChange”, line 1, in ?
ImportError: No module named axis

at org.python.core.Py.ImportError(Py.java)
at org.python.core.imp.import_logic(imp.java)
at org.python.core.imp.import_name(imp.java)
at org.python.core.imp.importName(imp.java)
at org.python.core.ImportFunction.load(__builtin__.java)
at org.python.core.ImportFunction.__call__(__builtin__.java)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.core.__builtin__.__import__(__builtin__.java)
at org.python.core.imp.importFromAs(imp.java)
at org.python.core.imp.importFrom(imp.java)
at org.python.pycode._pyx21.f$0(<event:propertyChange>:1)
at org.python.pycode._pyx21.call_function(<event:propertyChange>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.factorypmi.application.script.ScriptManager.runCode(ScriptManager.java:245)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:145)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:287)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
at $Proxy1.propertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at javax.swing.JComponent.firePropertyChange(Unknown Source)
at com.inductiveautomation.factorypmi.application.components.PMIComboBox$1.actionPerformed(PMIComboBox.java:124)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at com.inductiveautomation.factorypmi.application.components.PMIComboBox.contentsChanged(PMIComboBox.java:152)
at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
at com.inductiveautomation.factorypmi.application.components.PMIComboBox$DataSetComboBoxModel.setSelectedItem(PMIComboBox.java:571)
at com.inductiveautomation.factorypmi.application.components.PMIComboBox.setSelectedItem(PMIComboBox.java:140)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

What version are you running?

3.3.0

Sorry, try this:

import sys sys.add_package("org.jfree.chart.axis") from org.jfree.chart.axis import NumberTickUnit from java.text import DecimalFormat chart = event.source.parent.getComponent("Chart") axis= chart.getChart().getPlot().getRangeAxis() axis.setTickUnit(NumberTickUnit(.005, DecimalFormat("#.000")))

Thanks Carl. The code worked out beautifully. I did make a slight change for when the range becomes really big. Otherwise I found there to be alot of tick marks on the Y-axis when it was set to every .005.

Here is the code I used to set the length between tick marks dynamically.

import sys
	sys.add_package("org.jfree.chart.axis")
	from org.jfree.chart.axis import NumberTickUnit
	from java.text import DecimalFormat
	chart = event.source.parent.getComponent("Chart")
	axis= chart.getChart().getPlot().getRangeAxis()
	autoRange = axis.getRange()  #<-----------------------------added
	autoRangeLength = autoRange.getLength()/5    #<--------------------------added
	axis.setTickUnit(NumberTickUnit(round(autoRangeLength,3), DecimalFormat("#.000"))) #<-added the round(autoRangeLenght,3)

Nicely done!