ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Re: Could you please help on how to use chart director in Maven project
Posted by Tom Tra on Jul-15-2016 23:37
Hello,
   I am new to Chart Director , and I would like to seek help if anyone had used Chart Director in a maven project. I am looking for including Chart Director dependencies into my Eclipse Maven project , but I do not know what is group id, version of jar file that I need to have in my pom.xml. Beside including Chart Director in POM.xml, I also have a question if anyone has a sample code of  showing how to forward the chart object; for example bar graph, to a jsp view using simple Spring MVC .  if you happen to know , please share it with me   and I am very appreciative of   all of your helps.

Many thanks,
Tom

  Re: Could you please help on how to use chart director in Maven project
Posted by Peter Kwan on Jul-16-2016 04:54
Hi Tom,

I am not familiar with Spring MVC. In general, to ChartDirector in MVC, you can create the chart in the controller, and stores the "result" into suitable variables. You can then use the "result" in the View.

As an example, consider the "Simple Bar Chart" sample code. The original sample code is like:

... code to create chart here ....

// Output the chart
String chart1URL = c.makeSession(request, "chart1");

// Include tool tip for the chart
String imageMap1 = c.getHTMLImageMap("", "", "title='{xLabel}: {value} GBytes'");

Note that the last 2 lines are to create the image URL and the image map for the chart. In JSP, these two variables are then used in the HTML part of the code as follows:

<img src="getchart.jsp?<%=chart1URL%>" usemap="#map1" border="0">
<map name="map1"><%=imageMap1%></map>

In MVC, the charting part of the code is in the controller. The chart1URL and imageMap1 can be put in same "attributes", like:

model.addAttribute("chart1URL", chart1URL);
model.addAttribute("imageMap1", imageMap1);

Then in the View JSP, you may use them like:

<img src='getchart.jsp?$(chart1URL)' usemap="#map1" border="0">
<map name="map1">$(imageMap1)</map>


The original charting code uses the HttpServletRequest object. I searched the Internet and I found a page that mentioned for Spring, you need to add the following line to your class to make this object avaiable:

@Autowired
private HttpServletRequest request;

Note that I am not familiar with Spring and so I do not know if the above code is exactly correct. It is just to show the idea how to port from JSP to MVC. Basically, it is to store the "result" (the image URL "chart1URL" and the image map "imageMap1") into suitable "variables" or "attributes", which can then be used in the View.

Sorry, I am not familiar with Maven as well, but I think the ChartDirector.jar can just be installed and configured like any other third party JAR file that you use in your controller code.

Regards
Peter Kwan