Illegal type for X value: class java.lang.String (column 'Date')

Hi all,

I’m trying to get a chart to graph my data that is stored inside a memory tag. I think there are differences between my values and what it wants as a date format. I tried using the chart Chart Customizer to change the X-axis to a symbol axis with no luck. Is there any way I can bypass the date format to graph my dates inside Ignition?

Here is a picture of the error ignition is throwing and what the format of my memory tag looks like.

You could use this code in a propertyChange script to convert your string to a date:

from java.text import SimpleDateFormat

# set the format of the date string
format = SimpleDateFormat("MM/dd/yyyy")

# get the raw data
ds = event.source.parent.RawData     # This is your memory tag in a CustomProperty
ds2 = system.dataset.toPyDataSet(ds)

newRows = []
if len(ds2) > 0:
	# convert each row
	for row in ds2:
		dateStamp = format.parse(row[0])
		newRows.append([dateStamp, row[1]])
		
# create the new dataset
headers = ['Date', 'Value']
newDS = system.dataset.toDataSet(headers, newRows)

# write it to the Chart
event.source.parent.getComponent('Chart').Data = newDS

Thanks @DavidWisely this is very helpful.

I do have a quick question on line 7

I’m a little confused about the path to get to the memory tags dataset. Woulld something like this work?

ds = event.system.tag.read("tagPath").value

Also to build on my first question, where is the best place to place this code? Under a Button property change event? Under the chart property event? Or is there a better place?

So I have made a little more progress on this problem. I placed David’s code under a button and replaced line 7 with
ds = system.tag.read("tagPath").value
This seemed to get rid the “Illegal type for X value” error but threw a new error “Illegal type for Y value”. I figured this is the same string problem the X value had before being parsed.

I figured i’d try repeating the same parsing process as done with SimpleDateFormat using NumberFormat but unfortunately I’m not to familiar with Java Script.

Hi Agweb,

As always, there are a few ways to do it, this is just one:

Add a Custom Property of type Dataset to the root container. Call it GrowingDays, and bind it to your GrowingDays tag:

On the root container, add a propertyChange script:

Now, every time the GrowingDays tag changes, it will update the data on the chart with the reformatted dataset!

With your second error, it sounds like you the column ‘GDD’ is of type ‘String’ and you need to convert it to type ‘integer’, I’ve added this to the script above.

Note: It would be better to make sure your data types are correct when your original dataset is created. This is really just a work around so it will work with the chart.

Ah I see. int() doesnt work alone because I have whole numbers but I just used int(float()).
I did it a little different under a button but this solution works.

from java.text import SimpleDateFormat

# set the format of the date string
format = SimpleDateFormat("MM/dd/yyyy")

# get the raw data
ds = system.tag.read("Growing Days").value     # This is your memory tag in a CustomProperty
ds2 = system.dataset.toPyDataSet(ds)

newRows = []
if len(ds2) > 0:
	# convert each row
	for row in ds2:
		dateStamp = format.parse(row[0])
		newRows.append([dateStamp, int(float(row[1])), int(float(row[2]))])
		
# create the new dataset
headers = ['Date', 'Growing Degree Days', 'Harvest Line']
newDS = system.dataset.toDataSet(headers, newRows)

# write it to the Chart
event.source.parent.getComponent('Chart').Data = newDS

Thanks for the help!