In order to add the trendlines object you have to create a array list which will prepare the trendline object and will call a method to build the internal structure of the trendline object, inside the method you will have to create a hashmap which will add as key value pairs, inside that hashmap you need to create a arraylist which store the data of the line objects, inside the line object the data shuld be in key value pairs so in order to do that you will have to create a hashmap for it, finally you need to add this hashmap with the line arraylist object, and finally this arraylist object will be added to the primary hashmap and will return it.
Please refer this Dropbox for a sample using database https://www.dropbox.com/s/04dwugo4unw5uin/Fusioncharts_trendline_sample.zip?dl=0
You will get the sql table from the project inside the sql folder.
Also you can check the code snippet below
<%
//prepare trendlines
ArrayList trendlines= new ArrayList();
trendlines.add(buildTrendlines("startvalue","color","displayvalue",gson));
//close the connection.
result.close();
//create 'dataMap' map object to make a complete FusionCharts datasource.
Map<String, String> dataMap = new LinkedHashMap<String, String>();
/*
gson.toJson() the data to retrieve the string containing the
JSON representation of the data in the array.
*/
dataMap.put("chart", gson.toJson(chartobj));
dataMap.put("categories", gson.toJson(categories));
dataMap.put("dataset", gson.toJson(dataset));
dataMap.put("trendlines",gson.toJson(trendlines));
FusionCharts mslineChart= new FusionCharts(
"msline",// chartType
"chart1",// chartId
"600","400",// chartWidth, chartHeight
"chart",// chartContainer
"json",// dataFormat
gson.toJson(dataMap) //dataSource
);
%>
<%!
public Map buildTrendlines(String startvalue, String color, String displayvalue, Gson gson){
Map<String, String> trendlineinner = new HashMap<String, String>();
ArrayList lines = new ArrayList();
Map<String, String> linesdata = new HashMap<String, String>();
linesdata.put("startvalue", "17022");
linesdata.put("color","#6baa01");
linesdata.put("displayvalue","Average");
lines.add(linesdata);
trendlineinner.put("line", gson.toJson(lines));
return trendlineinner;
}
%>
<%= mslineChart.render() %>