While still having this issue - http://primefaces.prime.com.tr/forum/vi ... 48&start=0 - I'm continuing work with the charts to get it working for me. I've discovered what I think is a bug. This is in the JSF 1.2-based version.
Here is a code segment:
Code: Select all
<p:lineChart value="#{searchBean.searchResult.rows}" var="row" xfield="#{row.xaxis}">
<c:forEach var="fieldName" items="#{searchBean.searchResult.fieldNames}">
<p:chartSeries label=" #{fieldName}" value="#{row.values[fieldName]}"/>
</c:forEach>
</p:lineChart>
Code: Select all
YAHOO.widget.Chart.SWFURL = '/SMSWeb/primefaces_resource/1.0.2/yui/charts/assets/charts.swf'</script><div id="mainform:j_id89" style="width:500px;height:350px"></div><script type="text/javascript">jQuery(document).ready(function(){widget_mainform_j_id89_data = [{xaxis:"2006",fieldName:15.0,fieldName:6.0,fieldName:43.0,fieldName:0.0,fieldName:0.0,fieldName:0.0,fieldName:0.0},
{xaxis:"2007",fieldName:23.0,fieldName:13.0,fieldName:19.0,fieldName:1.0,fieldName:1.0,fieldName:0.0,fieldName:0.0},
{xaxis:"2008",fieldName:26.0,fieldName:17.0,fieldName:53.0,fieldName:7.0,fieldName:0.0,fieldName:3.0,fieldName:0.0},
{xaxis:"2009",fieldName:23.0,fieldName:8.0,fieldName:38.0,fieldName:3.0,fieldName:0.0,fieldName:1.0,fieldName:1.0},
{xaxis:"2010",fieldName:3.0,fieldName:1.0,fieldName:14.0,fieldName:1.0,fieldName:0.0,fieldName:0.0,fieldName:0.0}];
var widget_mainform_j_id89_dataSource = new YAHOO.util.DataSource(widget_mainform_j_id89_data);
widget_mainform_j_id89_dataSource.responseType=YAHOO.util.DataSource.TYPE_JSARRAY;
widget_mainform_j_id89_dataSource.responseSchema = {fields:["xaxis","fieldName","fieldName","fieldName","fieldName","fieldName","fieldName","fieldName"]};
var widget_mainform_j_id89_seriesDef = [{displayName:' B727', yField:'fieldName'},{displayName:' CB737', yField:'fieldName'},{displayName:' [none]', yField:'fieldName'},{displayName:' B747', yField:'fieldName'},{displayName:' B757', yField:'fieldName'},{displayName:' B767', yField:'fieldName'},{displayName:' B777', yField:'fieldName'}];
var yAxis = new YAHOO.widget.NumericAxis();
var xAxis = new YAHOO.widget.CategoryAxis();
widget_mainform_j_id89 = new YAHOO.widget.LineChart('mainform:j_id89',widget_mainform_j_id89_dataSource,{xField:'xaxis',series:widget_mainform_j_id89_seriesDef,expressInstall:'/SMSWeb/primefaces_resource/1.0.2/yui/assets/expressinstall.swf',xAxis:xAxis,yAxis:yAxis});
});
Code: Select all
for (ChartSeries axis : series) {
ValueExpression ve = axis.getValueExpression("value");
String fieldName = getFieldName(axis.getValueExpression("value"));
writer.write("," + fieldName + ":" + ve.getValue(facesContext.getELContext()).toString()); //TODO: Use converter if any
}
Now getting back to my example. For me, p:chartSeries is in a loop. It takes the "value" parameter, which in my case is "#{row.values[fieldName]}". It cuts out "fieldName" and uses that as the variable name ... for ALL rows! Since all variables in a row have the name "fieldName", the last one wins, and there is only one data series drawn.
Can there be another way of setting the field name? "label" is nice for a user displayed value, but there needs to be something else for the generated JavaScript variable name.
I thought of two possibilities to change the behavior.
SUGGESTION #1: add an attribute to specify the JavaScript variable name:
<p:chartSeries label="" value="" variable=""/>
If the variable weren't specified, it would default back to the current behavior, which would retain compatibility. You would probably have to change all of the chart objects to support the new attribute.
SUGGESTION #2: change the algorithm that determines the variable name. Maybe make it based on the label, to lowercase, spaces to _, minus / dash ("-") to _, and maybe other special characters to underscore. Code written for the old version *SHOULD* still work, although there might be some weird cases where it wouldn't. It would probably only involve changing the getFieldName() method, although it would have to pass in the label as well as the value.
ETA: SUGGESTION #3: Forget reasonable names for variables, just make them "field1", "field2", "field3", etc. This is probably the most reliable for users of the components.
Regards,
Chris