cancel
Showing results for 
Search instead for 
Did you mean: 

Business Graphics:Create multiple Pie charts dynamically

Former Member
0 Kudos

Hi Experts,

I have a requirement to create 10 different pie chart in a view in a Grid layout.

The charts will be created dynamically because the data will be known at runtime.

Any type of help will be appreciated

Regards.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Here is a simple example:

you must write this code in wdDoModfy() method, in if (firstTime){}

in the layout there is already created one transperent container with id BG_CONTAINER


//add a node
IWDNodeInfo loDynNode = wdContext.getNodeInfo().addChild("DynNode", null, true, false, true, false, false, true, null, null, null);
//add some attributes to it
		loDynNode.addAttribute("DynAttr1Str", "ddic:com.sap.dictionary.string");
		loDynNode.addAttribute("DynAttr2Int", "ddic:com.sap.dictionary.integer");

//get the node
		IWDNode node = wdContext.getChildNode("DynNode", 0);

//fill the node with some values
		for (int i = 0; i < 10; i ++){
			IWDNodeElement element = node.createElement();
			element.setAttributeValue("DynAttr1Str", "Str value " + i);
			element.setAttributeValue("DynAttr2Int", new Integer(i));
			// Add to the content
			node.addElement(element);
		}

//get the attributes, we will use the attrinfo to bind them to the series
		IWDAttributeInfo loDynAttr1StrInfo = loDynNode.getAttribute("DynAttr1Str");
		IWDAttributeInfo loDynAttr2IntInfo = loDynNode.getAttribute("DynAttr2Int");
		
//create the graphics
		IWDBusinessGraphics loGraphics = (IWDBusinessGraphics)view.createElement(IWDBusinessGraphics.class,"bg1");
//set the type to pie
		loGraphics.setChartType(WDBusinessGraphicsType.PIE);
//create a simple series and bind the integer attribute to it
		IWDSimpleSeries loSSeries = (IWDSimpleSeries)view.createElement(IWDSimpleSeries.class, "Series1");
		loSSeries.bindValue(loDynAttr2IntInfo);
//create the  category and bind the string attribute to it
		IWDCategory loCategory = (IWDCategory)view.createElement(IWDCategory.class,"Category1");
		loCategory.bindDescription(loDynAttr1StrInfo);
//add series and category
		loGraphics.addSeries(loSSeries);
		loGraphics.setCategory(loCategory);

//I assume that there is a transperent container already created design time to put the graphics there 
//container with id BG_CONTAINER
		IWDTransparentContainer loContainer =  (IWDTransparentContainer)view.getElement("BG_CONTAINER");
//add the graphics
		loContainer.addChild(loGraphics);

If this is the type of graphics you need then you must simply do a for cycle and supply the graphics with the right node elements and you are ready.

Best regards,

Anton

Former Member
0 Kudos

Hi Anton, I've tried as you suggested. But the graph is not being displayed .

The screen is showing empty

Former Member
0 Kudos

Yeah, the no. of Charts will depend on the data

Former Member
0 Kudos

HI Anton, thanx for ur suggestion 10 pts for you

Answers (1)

Answers (1)

Former Member
0 Kudos

What does that mean: "because the data will be known at runtime"? Is the number of charts depending on the data?

Armin