seriesCaptions=new LinkedHashMap();
String res=DataSetAccessFunctions.getDataSetResultFromId(profile, getData(),parametersObject);
categories=new HashMap();
DatasetMap datasetMap=new DatasetMap();
SourceBean sbRows=SourceBean.fromXMLString(res);
List listAtts=sbRows.getAttributeAsList("ROW"); // One row for each category
categoriesNumber=0;
// 4 datasets, 2 for first axis named 1, 2 for second axis named 2
datasetMap.getDatasets().put("1-bar", new DefaultCategoryDataset());
datasetMap.getDatasets().put("1-line", new DefaultCategoryDataset());
datasetMap.getDatasets().put("2-bar", new DefaultCategoryDataset());
datasetMap.getDatasets().put("2-line", new DefaultCategoryDataset());
lineNoShapeSeries1=new Vector<String>();
lineNoShapeSeries2=new Vector<String>();
categoriesTooltip=new HashMap<String, String>();
seriesTooltip=new HashMap<String, String>();
seriesOrder=new ArrayList<String>();
boolean first=true;
//categories.put(new Integer(0), "All Categories");
for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) { // run all categories (one for each row)
SourceBean category = (SourceBean) iterator.next();
List atts=category.getContainedAttributes(); // attributes: x is category name, values as serie_name are others, addition values can be added
HashMap series=new LinkedHashMap();
HashMap additionalValues=new LinkedHashMap();
String catValue="";
String nameP="";
String value="";
if(first){
if (name.indexOf("$F{") >= 0){
setTitleParameter(atts);
}
if (getSubName()!= null && getSubName().indexOf("$F") >= 0){
setSubTitleParameter(atts);
}
first=false;
}
//run all the attributes, to define series!
int numColumn = 0;
for (Iterator iterator2 = atts.iterator(); iterator2.hasNext();) {
numColumn ++;
SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next();
// In order to have tootltip for category they must be defined after x
nameP=new String(object.getKey());
value=new String((String)object.getValue());
if(nameP.equalsIgnoreCase("x")) // category name
{
catValue=value;
categoriesNumber=categoriesNumber+1;
categories.put(new Integer(categoriesNumber),value);
}
else {
if(nameP.toUpperCase().startsWith("ADD_")){ // additional information
if(additionalLabels){
String ind=nameP.substring(4);
additionalValues.put(ind, value);
}
} // must be after x definition
else if((nameP.toUpperCase()).startsWith("TIP_X")){ // additional information
if(enableToolTips){
categoriesTooltip.put(nameP.toUpperCase()+"_"+catValue, value);
}
}
else if(nameP.toUpperCase().startsWith("TIP_")){ // additional information
if(enableToolTips){
seriesTooltip.put(nameP.toUpperCase(), value);
}
}
else if(nameP.toUpperCase().startsWith("FREETIP_X")){ // additional information
if(enableToolTips){
freeToolTips=true; //help the search later in MyCategoryToolTipGenerator
categoriesTooltip.put(nameP.toUpperCase()+"_"+catValue, value);
}
}
else{
if(seriesLabelsMap!=null){ // a serie
String serieLabel = (String)seriesLabelsMap.get(nameP);
series.put(serieLabel, value);
if(!seriesOrder.contains(serieLabel)){
seriesOrder.add(serieLabel);
}
seriesCaptions.put(serieLabel, nameP);
}
else {
series.put(nameP, value);
if(!seriesOrder.contains(nameP)){
seriesOrder.add(nameP);
}
}
}
// for now I make like if addition value is checked he seek for an attribute with name with value+name_serie
}
}
// for each serie
for (Iterator iterator3 = series.keySet().iterator(); iterator3.hasNext();) {
String nameS = (String) iterator3.next();
String labelS = "";
String valueS=(String)series.get(nameS);
Double valueD=null;
try{
valueD=Double.valueOf(valueS);
}
catch (Exception e) {
logger.warn("error in double conversion, put default to null");
valueD=null;
}
if(!hiddenSeries.contains(nameS)){
if(seriesLabelsMap != null && (seriesCaptions != null && seriesCaptions.size()>0)){
nameS = (String)(seriesCaptions.get(nameS));
labelS = (String)seriesLabelsMap.get(nameS);
if(labelS==null)labelS=nameS;
}
else
labelS = nameS;
// Fill DATASET: Check if has to be filled dataset 1 or dataset 2, to bar or lines
// LINE CASE
if(!isHiddenSerie(nameS) && seriesDraw.get(nameS)!=null &&
(((String)seriesDraw.get(nameS)).equalsIgnoreCase("line") || ((String)seriesDraw.get(nameS)).equalsIgnoreCase("line_no_shapes"))
)
{
if(!seriesNames.contains(nameS))seriesNames.add(nameS);
// SET THE AXIS
if(seriesScale != null && seriesScale.get(nameS)!=null && ((String)seriesScale.get(nameS)).equalsIgnoreCase("2")){
useLinesRenderers=true;
if(((String)seriesDraw.get(nameS)).equalsIgnoreCase("line_no_shapes") && !lineNoShapeSeries2.contains(nameS)){
lineNoShapeSeries2.add(nameS);
}
((DefaultCategoryDataset)(datasetMap.getDatasets().get("2-line"))).addValue(valueD!=null ? valueD.doubleValue() : null, labelS, catValue);
}
else{
useLinesRenderers=true;
if(((String)seriesDraw.get(nameS)).equalsIgnoreCase("line_no_shapes") && !lineNoShapeSeries1.contains(nameS)){
lineNoShapeSeries1.add(nameS);
}
((DefaultCategoryDataset)(datasetMap.getDatasets().get("1-line"))).addValue(valueD!=null ? valueD.doubleValue() : null, labelS, catValue);
}
}
else if(!isHiddenSerie(nameS)){// BAR CASE
if(!seriesNames.contains(nameS))seriesNames.add(nameS);
// if to draw mapped to first axis
if(seriesScale != null && seriesScale.get(nameS)!=null && ((String)seriesScale.get(nameS)).equalsIgnoreCase("2")){
if(!seriesNames.contains(nameS))seriesNames.add(nameS);
((DefaultCategoryDataset)(datasetMap.getDatasets().get("2-bar"))).addValue(valueD!=null ? valueD.doubleValue() : null, labelS, catValue);
}
else{ // if to draw as a bar
if(!seriesNames.contains(nameS))seriesNames.add(nameS);
((DefaultCategoryDataset)(datasetMap.getDatasets().get("1-bar"))).addValue(valueD!=null ? valueD.doubleValue() : null, labelS, catValue);
}
}
// if(!isHiddenSerie(nameS)){
// if(!seriesNames.contains(nameS))