Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
How to perform setDataMapping() in Bean Code?
posted

I try to build my LineChart completely in the bean code. Caption and legends of the charts appear but no axes, grid lines or data lines.
I guess one important problem is the data mapping, which I don't really know how to perform it in bean's code.

JSF code is only this: 
...
<ig:chart id="chart4" binding="#{myChart.chart}" />
...

JAVA Bean code is:

private void initChart() {
  if (chart == nullchart = new Chart();
  FacesContext context = FacesContext.getCurrentInstance();
  Application application = context.getApplication();
  MethodBinding dataPointListener1 = application.createMethodBinding(
 
"#{myChart.processDataPoint}", new Class[ { javax.faces.event.ActionEvent.class });
 
chart.setDataPointListener(dataPointListener1);
 
chart.setChartType("Line");
 
chart.setGroupType("Stack100");
 
chart.setProjectionType("2D");
 
chart.setStyle("width: 420; height: 320");
  Caption caption =
new Caption();
  caption.setCaption(
"2D Stack100 Line Chart 1");
 
caption.setPosition("top");
 
chart.setCaption(caption);
  Legend legend =
new Legend();
  legend.setPosition(
"right");
  legend.setAutoItems(
true);
 
chart.setLegend(legend);
  Axis xAxis = new Axis();
  xAxis.setType(AxisType.
X.toString());
 
xAxis.setAutoRange(true);
  xAxis.setAutoRangeSnap(
false);
  xAxis.setAutoTickMarks(
true);
  xAxis.setAutoGridLines(
true);
 
chart.getChildren().add(xAxis);
  xAxis.setParent(
chart);
  Axis yAxis =
new Axis();
  yAxis.setType(
"y");
  yAxis.setAutoRange(
true);
 
yAxis.setAutoRangeSnap(true);
  yAxis.setAutoTickMarks(
true);
  yAxis.setAutoGridLines(
true);
 
chart.getChildren().add(yAxis);
  yAxis.setParent(
chart);
 
for (int i = 0; i < 3; ++i) {
    Series series =
new Series();
    series.setChartType(ChartType.
LINE.toString());
    NumbersSource data = new NumbersSource();
    ScalarDataModel model =
new ScalarDataModel();
    model.setWrappedData(data.getSparse0());
    series.setDataSource(model);

  
// series.setDataMapping( "value: column0" );

   chart.getChildren().add(series);
  }
 
chart.dataBind(context);
}

- If I activate the line with series.setDataMapping I get the follwing error:

>> WARN Coercions:513 - Ausnahmefehler beim Versuch, String "column0" in Typ "java.lang.Integer" zu konvertieren
>> ERROR ArraySuffix:181 - Dem Operator "." wurde ein Indexwert vom Typ "java.lang.String" zur Anwendung auf eine Liste oder einen Array
>> übergeben; der Wert konnte jedoch nicht in eine ganze Zahl konvertiert werden.
>>17:49:47,593 DEBUG ValueBindingImpl:188 - getValue Evaluation threw exception:
>>
javax.faces.el.ReferenceSyntaxException: Dem Operator "." wurde ein Indexwert vom Typ "java.lang.String" zur Anwendung auf eine Liste oder
>> einen Array übergeben; der Wert konnte jedoch nicht in eine ganze Zahl konvertiert werden.
>>
at com.sun.faces.el.impl.ArraySuffix.evaluate(ArraySuffix.java:183)

The code of the original trial (LineChart) is:

<ig:series markerBulletVisible="true" legendCaption="#{webchart_numbersSource.name1}"
   dataMapping="value: column0; tooltipCaption: caption" dataSource="#{webchart_numbersSource.sparse1}" />
<ig:series markerBulletVisible="true" legendCaption="#{webchart_numbersSource.name2}"
  
dataMapping="value: column0; tooltipCaption: caption" dataSource="#{webchart_numbersSource.sparse2}" />

So my questions are:
- Does anybody know if the missing data mapping is the problem, that no data and axes is displayed?
- How can I set a valid DataMapping in above listed code?

Best regards, Andrea

Parents
No Data
Reply
  • 1045
    Offline posted

    Hi Andrea,

    Instead of using a ScalarDataModel, you should use a ListDataModel.

    for (int i = 0; i < 3; ++i) {

    Series series = new Series();

    series.setChartType(ChartType.LINE.toString());

    NumbersSource data = new NumbersSource();

    ListDataModel model = new ListDataModel();

    model.setWrappedData(data.getSparse0());

    series.setDataSource(model);

     

    series.setDataMapping(
    "value: column0" );

     

    chart.getChildren().add(series);

    }

     

    Regards,

    Pamela Brasil

    Technical Documentation Specialist.

Children
No Data