Easy Chart Xtrace & Mark Mode datetime format

I would like to be able to change the time format in a Vision Easy Chart of the xtrace & mark mode labels to something like, yyyy/MM/dd h:mm:ss a z

I can format the time & place it on the value label of the xtrace label but am unable to change the datetime label , while I can't format anything in Mark mode label

From other looking at discussions here, I have been able to do it for the tooltip using the code below in a configureChart extension

from java.text import SimpleDateFormat
from org.jfree.chart.labels import StandardXYToolTipGenerator

xFormat = SimpleDateFormat("yyyy/MM/dd h:mm:ss a z")

# set the tooltip    
renderer = chart.getPlot().getRenderer()
yFormat = renderer.getBaseToolTipGenerator().getYFormat().getInstance()
#xFormat = renderer.getBaseToolTipGenerator().getXDateFormat().getDateInstance()
renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator("{1} Value {2}", xFormat , yFormat))
1 Like

Interesting problem. I'm not yet sure how to go about this, but looking through the StandardXYItemRenderer Java docs, the protected updateCrossHairValues method seems promising.

So far, I have not figured this problem out, but here is what I've learned so far:

There is an exposed property that can change the crosshair label's date format in an Easy Chart, but the desired setting appears to be defective.
In the Vision Property Editor under Historical Range, there is a property called Date Style:

Changing this to MDY has the following effect:

Similarly, changing this to DMY has this effect:

Inexplicably, changing this to YMD produces the following undesired result:

Programmatically, this property can be accessed directly from the domainAxis with the setDateStyle method:

#configureChart extension function
domainAxis = chart.getPlot().getDomainAxis()
#domainAxis.setDateStyle(0) = MDY
#domainAxis.setDateStyle(1) = DMY
#domainAxis.setDateStyle(2) = YMD

...but changing the date style this way yields the exact same result as above

Looking through the declared fields for the domain axis, the mdyFormat, mdFormat, and yFormat fields proved to be SimpleDateFormats that seemed to correlate to the date styles, but assigning a properly formatted SimpleDateFormat to these fields had no effect on the crosshair label.

The domain axis does have a dateFormatOverride method that changes the tick mark labels, but this does not effect the crosshair label.

I developed a work around that produces the desired effect by overriding the AutoTickDisplayDateAxis extension of the DateAxis and subsequently customizing the plot's date and time formats.

Here is the code:

def configureChart(self, chart):
	from java.text import SimpleDateFormat
	from org.jfree.chart.axis import DateAxis
	pureDateFormat = SimpleDateFormat("yyyy/MM/dd")
	pureTimeFormat = SimpleDateFormat("h:mm:ss a z")			
	dateAxis = DateAxis()
	plot = chart.getPlot()
	plotField1 = plot.getClass().getDeclaredField('dateFormat')
	plotField2 = plot.getClass().getDeclaredField('timeFormat')
	plotField1.set(plot, pureDateFormat)
	plotField2.set(plot, pureTimeFormat)

Here is the XTrace Mode result:

Here is the Mark Mode result:

I made X-Trace mode in my NoteChart module cover all of this customization, partly with extension methods. Sorry, but I did not rework Marker mode.

When I get time, I need to test the setDateStyle method on other versions. The date formatting for the YMD setting is clearly an unexpected behavior that needs to be corrected.

Thanks very much Justin, this is a huge help

1 Like