Easychart Axis Change

I am trying to programatically change the axis used for the easychart in a window. Depending on the product chosen the y-axis needs to have different minimum and maximum values, all the rest stays the same. Can that be done?

Yes, you’d have to do it by modifying the axes dataset on the easychart. Like most dataset modification, this involves copying the existing dataset into a PyDataSet, and then creating a new dataset with a list of lists and a list of column headers through a call to fpmi.db.toDataSet.

We realize that this is a bit verbose and confusing - we’re trying to think up a cleaner way to let users do dataset modification, but until then, this script would do it. This script would change the lower bound and upper bound on an axis called “Default Axis”. You’d have to add your own logic in there to toggle between various bounds based on a selected product. Let us know if you need help doing that:

[code]chart = event.source.parent.getComponent(“Easy Chart”)
axes = fpmi.db.toPyDataSet(chart.axes)

newRows = []
newColumnHeaders = []

for axis in axes:
newRow = []
myAxis = 0
for c in range(len(axis)):
colName = chart.axes.columnNames[c]
value = axis[c]
if len(newRows)==0:
# first axis - initialize column headers
newColumnHeaders.append(colName)
if colName==‘NAME’ and value == ‘Default Axis’:
# this is the axis I want to change
myAxis=1
if colName==‘LOWER_BOUND’ and myAxis==1:
value = 3800
if colName==‘UPPER_BOUND’ and myAxis==1:
value = 4100
newRow.append(value)
newRows.append(newRow)

chart.axes = fpmi.db.toDataSet(newColumnHeaders, newRows)[/code]

Hope this helps,

Thanks Carl.
It is indeed a little bit more that I had hoped for, but it will do. It would be nice if the axes values were available in the properties…

Jan

Yeah, that doesn’t really work because you can add multiple axes, even dynamically (they could be loaded from the database at runtime through a SQL query, for instance), so they can’t really be standard properties.

An easier way to edit datasets is definately in order.

If I make multiple axes on the easychart, can I dynamically change axis, depending on the product?

Of course. All easy chart axes are defined in that “Axes” dataset - you can manipulate it any way you want. Pens reference the axis they use by name.

OK, I give up. I tried to change the axis dynamically but failed miserably. Can you guys point me in the right direction? Let’s say that I have 2 axes, 1 is called ref282 and the other ref298, how do I switch between those depending on a combobox where I select the product?

Thanks,

Jan

And you want to switch all of the pens between these two axes?

Yes. Just change the axis. Keep the pens.

Ok, so if you have 2 axes, and you want to switch all of your pens between the two, a script like this would do:

[code]chart = event.source.parent.getComponent(“Easy Chart”)
pens = fpmi.db.toPyDataSet(chart.pens)

newRows = []
newColumnHeaders = []

somehow get the name of the axis we want chosen

axisName = event.source.parent.getComponent(“Axis Chooser”).selectedStringValue

for pen in pens:
newRow = []
for c in range(len(pen)):
colName = chart.pens.columnNames[c]
value = pen[c]
if len(newRows)==0:
# first axis - initialize column headers
newColumnHeaders.append(colName)
if colName==‘AXIS’:
value = axisName
newRow.append(value)
newRows.append(newRow)

chart.pens = fpmi.db.toDataSet(newColumnHeaders, newRows)[/code]

Hope this helps,