0

I am dealing with a problem with annotatedtimelines. I have to draw some charts depending on the tab that the user is, so when the tab is changed I clean the current chart and draw the new data. But how to do that?

For now I am removing all the rows, but it is not working. Can someone help me?

here is the code:

...

//Creating Columns
dataTable.addColumn(ColumnType.DATETIME, "Time");
dataTable.addColumn(ColumnType.NUMBER, "Realtime Consumption");
dataTable.addColumn(ColumnType.NUMBER, "Historical Consumption");

//Create options
options.setDisplayAnnotations(false);
options.setDisplayZoomButtons(false);
options.setScaleType(AnnotatedTimeLine.ScaleType.FIXED);
options.setLegendPosition(AnnotatedTimeLine.AnnotatedLegendPosition.SAME_ROW);
options.setAllowRedraw(true);
options.setDisplayRangeSelector(false);
options.setFill(30);

//to parse the time
DateTimeFormat dtf = DateTimeFormat.getFormat("hh:mm:ss");

//For each item of the list
for(int i = 0; i < list.size(); i++){
    //get date
    Date date = new Date(list.getTimeAt(i));

    //get hh:mm:ss
    String time = date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();

    //add row
    dataTable.addRow();
    dataTable.setValue(dataTable.getNumberOfRows() - 1, 0, dtf.parse(time));
    dataTable.setValue(dataTable.getNumberOfRows() - 1, 2, list.getDataAt(i));
}



/**
 * To clean the chart
 */
public void cleanChart(){
    //Remove all rows
    this.dataTable.removeRows(0, dataTable.getNumberOfRows());
    //Redraw the chart
    this.draw(this.dataTable, this.options);
}

Thanks, Maurício


It is very strange, but I did it (that seems ok, because I'd create another datatable), and it still not working. The old data continues there.

I have a class that extends AnnotatedTimeLine, and the clean method is now:

/**
 * Method to clean the annotated time line
 */
public void clean() {
    //Create new table
    this.dataTable = DataTable.create();

    //Create columns
    this.dataTable.addColumn(ColumnType.DATETIME, "Time");
    this.dataTable.addColumn(ColumnType.NUMBER, "Data 1");
    this.dataTable.addColumn(ColumnType.NUMBER, "Data 2");

    //Redraw the chart with the same options
    this.draw(this.dataTable, this.options);
}

Any idea?

Thanks!

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
banduk
  • 107
  • 1
  • 7

1 Answers1

0

You need to recreate DataTable for your new data and don't need to do this.dataTable.removeRows(0, dataTable.getNumberOfRows());

I have something like this

public void reloadChart(List<SharedBean> list, String titleX) {
    viz.draw(getChartData(), getOptions(titleX));
}

private DataTable getChartData() {
    DataTable data = DataTable.create();


    data.addColumn(ColumnType.STRING, "column");
    data.addColumn(ColumnType.NUMBER, "value");

    data.addRows(list.size());

    int row = 0;
    int i = 0;
    for(SharedBean bean: list){
        ......
    }

    return data;
  }
Munawar
  • 64
  • 2
  • Can you try `public void clean() { //Create new table DataTable dataTable = DataTable.create(); //Create columns this.dataTable.addColumn(ColumnType.DATETIME, "Time"); this.dataTable.addColumn(ColumnType.NUMBER, "Data 1"); this.dataTable.addColumn(ColumnType.NUMBER, "Data 2"); //Redraw the chart with the same options this.draw(dataTable, this.options); }` – Munawar Aug 11 '11 at 17:59
  • It doesn't work yet.. 'public void clean() { DataTable data = DataTable.create(); data.addColumn(ColumnType.DATETIME, "Time"); data.addColumn(ColumnType.NUMBER, "Realtime Consumption"); data.addColumn(ColumnType.NUMBER, "Historical Consumption"); this.draw(data, this.options); this.dataTable = data; }' – banduk Aug 12 '11 at 16:38