Perspective xychart

Hello,

I have using XY Chart for show line running status

for the data i have binded the dataset tag. It contains starttime,endtime and some more columns.Then i have added "Add Transform" script for convert dataset to json. Then the endtime of the last row of dataset should be show current time. so, i have put script for same in "Add Transform" script.

now , my problem is:

  • when i added the new row in dataset the chart shows empty. but the output json changed with recent data in props.datasource.example property.

    if the property binding is refresh, it shows chart. I have using self .refreshBinding( "props.datasource.example" ). for refresh binding. but it is shows when the refresh is done by after one second delay .

  • Then the endtime of the last row is changed to current time when the propery binding is works. but i need the last row of end time should be always current time.

Any One Have A Idea Please Provide.

Thanks in advance!.

Please show a sample of your data and your transform code. (Paste as text and use the "Preformatted text" button in the forum editor to style it as code.)

This the Dataset i have binded:

:

script:

	num_rows = value.getRowCount()
	
	if num_rows > 0:
	
		# Get the last row index (0-based)
		last_row_index = num_rows - 1
		
		# Get the current date and time
		current_datetime = system.date.now()
		
		# Update the 'endtime' of the last row with the current date and time
		dataset = system.dataset.setValue(value, last_row_index, "end_time", current_datetime)
		row_count = dataset.getRowCount()
		result = []
		
		for x in range(row_count):
			event_id = dataset.getValueAt(x,0)
			reason = dataset.getValueAt(x,5)
			run_status = dataset.getValueAt(x,7)
			start_milli = system.date.format(dataset.getValueAt(x,1),'yyyy-MM-dd HH:mm:ss')
			end_milli = system.date.format(dataset.getValueAt(x,2),'yyyy-MM-dd HH:mm:ss')
			
			if run_status == 1:
				color = '#8aff8a'
			elif run_status == 0 and reason == '':
				color = '#808080'
			elif run_status == 0 and reason == 'reason1':
				color = '#0b84a5'
			elif run_status == 0 and reason == 'reson2':
				color = '#ffa056'
			elif run_status == 0 and reason == 'reason3':
				color = '#8dddd0'
	
			result.append({
				"color":  color,
				"fromDate": start_milli,
				"name" : "",
				"toDate" : end_milli,
				"event_id" : event_id
				})
		return result

You are turning your datetime objects into strings. Don't do that. Just pass them through directly from the dataset. (They will become 64-bit integer milliseconds in the json.)

Hello @pturmel ,

It is working!. But the tooltip shows only date format

image

i need HH:mm:ss (at least HH:mm)

image

image

btw careful for typo

Try setting xAxes.date.break.format.

From here:

https://docs.inductiveautomation.com/display/DOC81/Perspective+-+XY+Chart#PerspectiveXYChart-Properties

this topic has a bunch of examples of formats

1 Like

@pturmel

it is not working . already the format is with HH:mm

image

Thankyou!. @victordcq

it is working.

thank you @pturmel for your quick response.

can you both give solution/idea for the my 2 nd point?

  • Then the endtime of the last row is changed to current time when the propery binding is works. but i need the last row of end time should be always current time.

you could do the forming of this data in a seperate custom property and then do a structered binding to this custom prop and on a now(5000) (best choose a delay) which only changes the last value.

i wouldnt do it in the same script else you will have to loop through all the data every second(or whatever you delay is)

anyway for just a small delay this seems like a very render expensive thing to do... i wouldnt do it