Quick start
 
 Dynamic style
 
 Dynamic model
 
 Drill-down
 
 Real time
 
 Ajax
 
 Embedded
 
 
 
 
   Overview         Example         Source       

Often you want to give your users ability to choose the chart's presentation based on their preferences. One of the possible ways is to design a number of charts in WebCharts3D Designer, hardcode XML styles inside your JSP page and then use one of the styles based on the user's choice. This method can be usefull in some cases, but is limiting when you want to give your user more flexibility. The most flexible way is to construct chart's style object, modify it and then convert to XML. This page demostrates this approach.

In the beginning you need to decide how to preserve the chart's style between the requests. Different methods exist for this purpose including storing style in session object and using hidden fields. In this example we use hidden field named 'styleXML'.

When the request is received you need to construct chart's style object. For this, we check the value of styleXML parameter provided with the request. If it is not defined, we take the default chart's style. The default chart style can be created manually or from default XML representation generated by WebCharts3D Designer.

  String styleXML = request.getParameter("styleXML");
  MxFrameChartStyle style = (MxFrameChartStyle) MxChartStyle.read(styleXML != null 
						? styleXML 
						: defStyleXML,null);

NOTE. The above code assumes that the chart's type does not change between requests. If this were not the case - for example if you are changing the style from frame to pie chart, you would need to create a new instance of the correct chart's style and then copy the common values from one style to another:

  MxPieChartStyle style = new MxPieChartStyle();
  MxChartStyle.read(styleXML != null ? styleXML : defStyleXML,null).morphInto(style);

Once the style object is created you can modify it:

  String is3D = request.getParameter("is3D");
  style.is3D = "on".equalsIgnoreCase(is3D);

When you are not sure what attribute do you want to change, you can design the desired chart in WebCharts3D Designer, switch to XML style pane and then select "Java code" from the right-click mouse menu. Designer will show you the required Java code together with import statements.

Now you can use toXML() function to convert the object to XML, assign the result to you chart's style and produce the chart. The last step is to define styleXML hidden field (and other controls):

  <form name=StyleForm id=StyleForm method="POST">
    <input type=hidden name="styleXML" value="<%=myChart.style.replace('"', '\'') %>">
    <input type=checkbox name=is3D 
		<%=style.is3D ? "checked" : ""%>
		onclick="javascript:document.StyleForm.submit()" >Is 3D
  </form>

 

   Copyright © 1994-2008 GreenPoint, Inc. All rights reserved.