Vaadin: How to update a chart's data? - vaadin

I am difficulties finding a way to update a chart with new data.
One adds data to a chart using:
Configuration conf = chart.getConfiguration();
conf.addSeries(series);
But there is no corresponding "remove(series)"!?!
Thus, if I want to update the data being displayed and add another series I actually add another line (or bar-graph or whatever visualization I have chosen) to the chart, which is clearly NOT what I want/need.
My first attempt to overcome that was to get hold of the old data series and remove them from the chart, but with getSeries() I am only getting a non-modifyable copy of the existing series, so that attempt ended in a java.lang.UnsupportedOperationException.
Thus my question: how do I convince an existing chart to remove all old data series?
Don't tell me, that I need to recreate the entire chart-component each time, please!

You didn't mention any versions, but at least it used to be possible to remove items from the DataSeries itself. So instead of removing the series, you can just empty and repopulate it. Save the series reference when you set it. Alternatively you can e.g. create a new ArrayList from the unmodifiable list, make your changes there, and set the series again (using setSeries, not addSeries). Then calling chart.drawChart(); should trigger the re-draw.

Related

Adding a new row to DBTreeList at runtime

I'm a newbie to Delphi and coding itself and have an issue which I can't solve.
I have to create a Treelist based on values from a Database which I did in the design field, here is an example on how it looks:
. Now it needs to be able to insert a new row after giving it a description (which is labeled as 'bez') while running.
The most obvious way to do that in my mind is to right click on a parent field and be able to add a new child field, how can I achieve that?
Also at the end of a parent tree I need it to be able to open a script/file, is that possible too?

Columns order in ListGrid Smartgwt

How can I programmatically change the order of columns in ListGrid? I have search for an appropriate method in javadoc but found nothing. Is it possible?
Check out setViewState method and this example that saves and restores grid preferences (including column order). So in short, you are interested in getting viewState string from ListGrid data and using it. Remember to redraw grid after setting new viewState.

SmartGWT LiveGrid unable to apply style to grid records programmatically

I am using SmartGWT 2.5, specifically a ListGrid backed by a RESTDataSource.
The Server integration is achieved by way of a servlet, and I only need to implement fetchData(). The data is a List<Map<String, Object>> populated on the server side, converted into JSON and sent in the DSResponse. The Live grid backed by the datasource triggers a server fetch programmatically by way of grid.fetchData().
Requirement:
I wish to set a record base style (or custom style) based on the value of one of the record's attributes, which I send over from the server.
In order to do this, I have tried a DataArrivedHandler, where I iterate over the available rows, get the ListGridRecord from the grid using the row number, and use gridRecord.set_baseStyle(String stylename) or gridRecord.setCustomStyle(String stylename) to try and apply a greyed out css for that record. After this, I call grid.markForRedraw(), however to no effect. The CSS does not get applied.
I must mention that I have used the same css to grey out rows on a normal listGrid (no dataSource) very successfully.
Questions:
Is my strategy the right one?
Is there an alternative method to apply a style to a record based on an attribute value.
Your strategy is correct and I have successfully achieved your required functionality in code of mine. Make sure you are correctly getting the record and that the test attribute is present in it. I suggest a JSON.encode(record.getJsObj()) to see what your record actually is filled with. No need for markForRedraw() explicit call, as after the DataArrivedEvent has fired the ListGrid will redraw its view. Post a small code snippet if you need more help. Also as suggested from the comment from Alain, highlights might be another good option to look at.

Delphi: TAdoTable.Insert not really an Insert?

I have two ADO Tables linked as master/details tables, tblCategory (master) and tblItems (details). Both tables have its own grid, and displayed in the same form. I also have data aware controls (dbedits).
Say, currently I'm at: Category=Books, No of Items=10 records, and pointing at record number 5 in the grid. I want to add a new record to the item, so I use:
tblItems.Insert;
The problem is, instead of adding a new row, the grid and the db aware controls are showing the current record (rec No 5). Not inly that, it seems the record is in edit mode too. After I cancel it and repeat the Insert command, only then the new row appeared.
How to fix this, so each time I use tblItems.Insert it always add a new and empty row :)
Nevermind, I think I know what caused it. It's the db aware controls. After the insert command, user will input data. This makes the db aware control receives focus and it automatically sets its position to the current record and displays it.
The solution is to use non-db-aware controls instead, and set the behavior programatically

Adding a field to a cloned TClientDataset in DELPHI

Hi I have a master and cloned TClientData set
CdsCloned.CloneCursor(CdsMaster,true);
CdsMaster has two Fields 'SessionId' and ’UserID'
CdsCloned will have the same Fields
QUESTION: is it possible to add an extra field to CdsCloned without changing the CdsMaster ?
There are really two questions here: Can I add an extra TField, and can I add an extra data field.
When you clone a client dataset cursor, you end up with two TDataSet instances, each with their own collection of TFields, which share a single data store. You can certainly add additional TFields for things like calculated fields to one or the other without affecting the clone. There is no problem with doing this.
But remember, the original dataset and its clone share a single data store. You cannot change that data store without affecting the other dataset. If you add a new field to the data store, then that new data will be present in the store referenced by the original dataset, whether or not you have created any TField objects to read/write it. If this is starting to sound like a bad idea, well, that's what I'm thinking, too.
Finally, if you want the original dataset and its "clone" to have different data stores, then you can assign the Data property instead of using CloneCursor. When you do this, the data from the original is copied into the data store for the "clone", but the original and "clone" no longer share a single data store.

Resources