Chart Dataset Enabled Property

Is there any way to access a charts dataset enable/disable property?

I am trying to have some selection buttons that will eliminate specific pens from several plots in one chart. I can't use the easy chart because I need the database to be dynamically selected.

Yes. You can enabled/disable it using a scripting function on the chart. Here is an example:chart = event.source.parent.getComponent('Chart') chart.setDatasetEnabled("Data", 0)Just replace the “Data” with the name of the dataset you want to disable.

Yes! Thank you.

I looked through manual for this property and could not find anything. Is there a list of properties for components that is not listed in the manual?

This one is not documented right now but I made a note to put it in our system.

My script is not able to see a root container property to dynamically set this property.

Hi Mr. @Travis.Cox ,

Is there any way to enable/disable the datasets in the chart for ignition vision?

I had tried this way, but I got an error while triggering that condition. I had 4 datasets in that chart and I want to disable any one of these datasets in the chart.

Script:

	chart = event.source.parent.parent.getComponent('Chart').chart
	if event.source.selected:
		chart.setDatasetEnabled("Data", 0)
		chart.setDatasetEnabled("lines", 1)
		chart.setDatasetEnabled("shapes", 1)
	    
	else:
		chart.plot.rangeAxis.setAutoRange(True)
		chart.setDatasetEnabled("Data", 1)
		chart.setDatasetEnabled("lines", 0)
		chart.setDatasetEnabled("shapes", 0)

I put that script in the property change script in Checkbox. When I enable the Checkbow, required datasets should be enabled,d and other datasets should be disabled.

Error:

Traceback (most recent call last):
  File "<event:propertyChange>", line 9, in <module>
  File "<custom-function Range_Assigning>", line 10, in Range_Assigning
AttributeError: 'org.jfree.chart.JFreeChart' object has no attribute 'setDatasetEnabled'


Ignition v8.1.44 (b2024102210)
Java: Azul Systems, Inc. 17.0.12

Thanks,
Muniyandi D

You have an extra .chart at the end of your script's first line. Take that off for the .setDatasetEnabled() method to work.

Correct but you will need the .chart on this line:

chart.chart.plot.rangeAxis.setAutoRange(True)

For posterity, the function Travis originally mentioned (and a bunch of other utilities) are documented on this page:

Hi @pturmel, thank you for your suggestion. But I got an error after doing that regarding the suggestion you gave.

Script:

	chart = event.source.parent.parent.getComponent('Chart')
	if event.source.selected:
		chart.setDatasetEnabled("Data", 0)
		chart.setDatasetEnabled("lines", 1)
		chart.setDatasetEnabled("shapes", 1)
	    
	else:
		chart.plot.rangeAxis.setAutoRange(True)
		chart.setDatasetEnabled("Data", 1)
		chart.setDatasetEnabled("lines", 0)
		chart.setDatasetEnabled("shapes", 0)

Error:

Traceback (most recent call last):
  File "<event:propertyChange>", line 9, in <module>
  File "<custom-function Range_Assigning>", line 10, in Range_Assigning
AttributeError: 'org.jfree.chart.JFreeChart' object has no attribute 'setDatasetEnabled'

Thanks,
Muniyandi D

You have extra parentheses here.

Sorry, i mistakenly gives extra parentheses. Now, i had corrected @andrew.budaiev .

Script:

	chart = event.source.parent.parent.getComponent('Chart').chart
	if event.source.selected:
		chart.setDatasetEnabled("Data", 0)
		chart.setDatasetEnabled("lines", 1)
		chart.setDatasetEnabled("shapes", 1)
	    
	else:
		chart.plot.rangeAxis.setAutoRange(True)
		chart.setDatasetEnabled("Data", 1)
		chart.setDatasetEnabled("lines", 0)
		chart.setDatasetEnabled("shapes", 0)

But,, i got that same error again.

Error:

Traceback (most recent call last):
  File "<event:propertyChange>", line 1, in <module>
  File "<custom-function Range_Assigning>", line 10, in Range_Assigning
AttributeError: 'org.jfree.chart.JFreeChart' object has no attribute 'setDatasetEnabled'


Ignition v8.1.44 (b2024102210)
Java: Azul Systems, Inc. 17.0.12

You put the .chart back on the end of the first line. Take it off.

event.source.parent.parent.getComponent('Chart')

This gives you a reference to the Ignition chart component. That's what has the setDatasetEnabled method.

event.source.parent.parent.getComponent('Chart').chart

This gives you a reference to the underlying Jfreechart component. This has a variety of methods for changing rendering of the actual graphical chart, but does not have the setDatasetEnabled method you're trying to use.

Thank you, Mr. @pturmel for your suggestion. Finally, I got what I expected.

Thanks,
Muniyandi D

I understood Mr. @paul-griffith , Thanks for your suggestion.

Thanks,
Muniyandi D

Hello All - Same idea but I want to disable the component altogether. If my history source goes away the chart keeps throwing up errors regardless of whether I disable the dataset or not. Any thoughts?