Modified history graph

Hi All:

I am trying to modify the history graph you’ve made. Mostly it is a simplified version following your original plan.

I have a container cntDatasets with 7 checkboxes, each label representing a different series in the graph. Each series corresponds to a different dataset. I use the code below to determine if the checkboxes are checked, and if so to build a query, then use that query to populate a dataset on the graph.

root = fpmi.gui.getParentWindow(event).rootContainer
chart = root.getComponent(“Chart”)
Tank = event.source.parent.getComponent(“lblTank”).text
checkboxes = root.getComponent(“cntDatasets”).components
selectedCheckboxes = [cb for cb in checkboxes if cb.selected]
print len(selectedCheckboxes)
if len(selectedCheckboxes) > 0:
for cbNum in range(len(selectedCheckboxes)):
checkbox = selectedCheckboxes[cbNum]
query = “exec dbo.usp_TankHistory '” + Tank + “’,’” + + “’”
print query
chart.setDatasetEnabled(, len(selectedCheckboxes)>0)

This bonks on line 12, which is the “chart.setDatasetEnabled…” line.
This is, by the way, one line that I don’t understand: the second argument in this line according to the docs should be a bit value turning on or off the enabled property, but in your code from the goodie it appears to be something else. Can you explain this please?

The debug window shows:
exec dbo.usp_TankHistory ‘999’,‘Level’

which means it is recognizing all 7 checkboxes as being checked, but is not iterating through and building a query string past the first checkbox.

Any advice is appreciated. D. Lewis


Ok, lets tackle this one one step at a time.

First of all, when you post code, could you please enclose it in code tags? like this: [code]post your code here[/code]
That way, your indentation is preserved, and I’m not left scratching my head trying to tell where your blocks start and stop!

Next - you say you have 7 checkboxes, each representing a different series, each series corresponding to a different dataset. But then the rest of your code looks like it is trying to build a single query for a single dataset. Could you clarify this? Is there one dataset or multiple datasets defined on the chart component?

About line 12 - that second argument, len(selectedCheckboxis)>0 is indeed a bit, as the documentation suggests. The result of a logical expression (greater than, in this case) is a bit - true or false.

The reason your query isn’t building, is that you are assigning to the variable named query inside the loop. So with each loop iteration, you are overwriting whatever the query had before. If you go back and look at the original code for this button in the goodie, you will see that it is building the query using the += operator, which concatenates the string on the right-hand-side of the operator into the string on the left-hand-side.

Lastly, is the code you posted the entire code of your update/refresh button, or just a part of it? If it is just a part, please post back with the entire code block enclosed in code tags.

Ok, that was a bit of a fragmented response, but lets continue after these issues are cleared up.



OK, I should probably back up and describe how I have changed the approach of the goodie, because it seemed 1) like a bit of overkill for my first attempt and 2) didn’t seem to me to easily integrate into how the db tables are structured, and how I like to access data.

The graph has 7 possible series. They are shown in a container cntDatasets, and have checkboxes to trigger whether the user wants to see them on or off.

Each of these series maps to a dataset. Each dataset has its own sp, which returns an x (in this case a timestamp) and a value. In this particular graph all the x values are identical across the datasets, but in many other graphs they are not. The datasets are in the chart container, not the root. That was not a reasoned decision and I am happy to locate them on the root container or anywhere else. For a while I had them on the cntDataset, actually; the reason for that being when I was ‘re-doing’ your goodie I noticed you had named the checkbox container Datasets, so it seemed like an appropriate place to put my datasets. Probably faulty reasoning…

The datasets as defined do not have a query property. That was to be accomplished in the button click code. No problem hardcoding in something in the sqlquery screen if that is better.

All the sp’s require two parameters, tank and the value to be graphed. The tank number (a string, actually) is passed in when the window is opened, and is stored on the root container in a variable strTank and is also displayed in a label on the window. The value to be graphed parameter is supplied by the label of the various checkboxes.

So, the code below, modified from the goodie, is supposed to iterate through the checkboxes, and if they are checked create a query string, apply that to a dataset, execute the sp and provide its results to the graph to display. If the checkbox is not checked, none of that should happen, and the pen should be turned off. With all that in mind (sorry for the endless email…):

root = fpmi.gui.getParentWindow(event).rootContainer chart = root.getComponent("Chart") Tank = event.source.parent.getComponent("lblTank").text checkboxes = root.getComponent("cntDatasets").components selectedCheckboxes = [cb for cb in checkboxes if cb.selected] print len(selectedCheckboxes) if len(selectedCheckboxes) > 0: for cbNum in range(len(selectedCheckboxes)): checkbox = selectedCheckboxes[cbNum] query = "exec dbo.usp_TankHistory '" + Tank + "','" + + "'" print query chart.setDatasetEnabled(, len(selectedCheckboxes)>0) dataset.setPropertyValue("Query",query) fpmi.db.refresh(chart,

TIA. D. Lewis


Ok, I think that I understand what you’re trying to do now. Before we get into it, I’d like to offer up some general advice to you and anyone else reading this thread: The Chart Goodie was created to provide a way to make a chart screen that didn’t involve writing any SQL queries. It works well in the ‘normal case’, and is put together in a quite complex way in order to accomplish the goal of having the user not write any queries. It should not be taken as an example of how to put together your own chart screen. (I don’t blame people for thinking it is - we currently don’t have any other example of a chart screen availalble…) I’ve seen quite a few people now trying to modify the graph goodie for their own purposes and get quite tangled up, when if they had started from scratch putting together their own custom chart screen, they would have had much more success.

My advice would be to scrap the chart screen that was derived from the chart goodie, and lets put together a new one. Because of how you’re doing your charts, the script you’re trying to modify doesn’t make sense anymore (the last 3 lines of the script have to do with detecting if the dataset had any checkboxes selected to determine if that dataset should be active, but your datasets are active or not based on only 1 checkbox. There is a much easier way to do what you’re doing.)

Here is how I would put together the chart screen you’re going for:
[li]Create a new window. Put a Chart on it. Add 7 datasets to the Chart (using the chart customizer)[/li]
[li]Bind each dataset to your stored procedure query[/li]
[li]Configure your datasets as you please (map them to Y-Axes, change colors, put them on subplots, etc)[/li]
[li]Make a checkbox. Add a String custom property to it named “DSName”. This will be the name of the dataset (as entered in the chart customizer) that the checkbox will control.[/li]
[li]Add the following script to the checkbox’s itemStateChanged event:

isChecked = event.stateChange == event.SELECTED dsName = event.source.getPropertyValue("DSName") chart = event.source.parent.getComponent("Chart") chart.setDatasetEnabled(dsName, isChecked)[/li]
[li]Copy that checkbox 7 times. Fill in the “DSName” property to correspond with the names of your 7 datasets on the Chart.[/li][/ul]

Thats it - You will have a chart with 7 datasets that will be displayed or not based on the checkboxes.

I’d be very happy to design this window with you interactively over GoToMeeting if you’d like - just give us a call and ask for me.

Hope this helps,

Well, that was easy. I should have asked first! Thanks for your patience. David

No problem - sorry the goodie led you astray. I think I’ll put a warning on the goodie warning against modification :slight_smile: