怎么拼接FusionCharts的JSON格式的双轴图
1个回答
展开全部
2、设计源码
/**
*
* @title:DoubleYaxis.java
* @Package:com.you.utils
* @Description:<h3>一句话描述功能</h3>
* @author:游海东
* @date:2015-3-25下午8:06:57
* @version V1.0
*
*/
package com.you.utils;
import net.sf.json.JSONObject;
/**
*
* 项目名称:SSH
* 类名称:DoubleYaxis
* 类描述:
* 创建人:游海东
* 创建时间:2015-3-25下午8:06:57
* 修改人:游海东
* 修改时间:2015-3-25下午8:06:57
* 修改备注:
* @version V1.0
*
*/
public class DoubleYaxis
{
/**
*
* 方法名:transform
* 方法类型:ChartUtils
* 参数:@param str
* 参数:@return
* @return:StringBuilder
* @throws
*/
public static StringBuilder transform(String str)
{
return new StringBuilder(str);
}
/**
*
* 方法名:buildJson
* 方法类型:DoubleYaxis
* 参数:@return
* @return :JSONObject
* @throws
*/
public static JSONObject buildJson()
{
StringBuilder chartHead = new StringBuilder();
StringBuilder xAxis = new StringBuilder();
StringBuilder yAxisOne = new StringBuilder();
StringBuilder yAxisTwo = new StringBuilder();
//FusionChart中的chart
chartHead.append("{'chart':{'caption':'2014年销售水平分布','xaxisname':'月份','yaxisname':'销量','showvalues':'0'},'categories':[{'category':[");
for(int i=1;i<=12;i++)
{
xAxis.append("{'label':'").append(i).append("月'},");
}
yAxisOne.append("'dataset':[{'seriesname':'苹果','data':[");
yAxisTwo.append("{'seriesname':'橘子','parentyaxis':'S','data':[");
for(int j=1;j<=12;j++)
{
yAxisOne.append("{'value':'").append(j*100).append("'},");
yAxisTwo.append("{'value':'").append(j*200).append("'},");
}
chartHead.append(xAxis.toString().substring(0, xAxis.toString().length()-1))
.append("]}],")
.append(yAxisOne.toString().substring(0, yAxisOne.length()-1))
.append("]},")
.append(yAxisTwo.toString().substring(0, yAxisTwo.length()-1))
.append("]}]}");
JSONObject jsonobject = JSONObject.fromObject(chartHead.toString());
return jsonobject;
}
/**
*
* 方法名:main
* 方法类型:DoubleYaxis
* 参数:@param args
* @return :void
* @throws
*/
public static void main(String[] args)
{
System.out.println("FusionChart多系列图之双轴图:"+buildJson());
}
}
/**
*
* @title:DoubleYaxis.java
* @Package:com.you.utils
* @Description:<h3>一句话描述功能</h3>
* @author:游海东
* @date:2015-3-25下午8:06:57
* @version V1.0
*
*/
package com.you.utils;
import net.sf.json.JSONObject;
/**
*
* 项目名称:SSH
* 类名称:DoubleYaxis
* 类描述:
* 创建人:游海东
* 创建时间:2015-3-25下午8:06:57
* 修改人:游海东
* 修改时间:2015-3-25下午8:06:57
* 修改备注:
* @version V1.0
*
*/
public class DoubleYaxis
{
/**
*
* 方法名:transform
* 方法类型:ChartUtils
* 参数:@param str
* 参数:@return
* @return:StringBuilder
* @throws
*/
public static StringBuilder transform(String str)
{
return new StringBuilder(str);
}
/**
*
* 方法名:buildJson
* 方法类型:DoubleYaxis
* 参数:@return
* @return :JSONObject
* @throws
*/
public static JSONObject buildJson()
{
StringBuilder chartHead = new StringBuilder();
StringBuilder xAxis = new StringBuilder();
StringBuilder yAxisOne = new StringBuilder();
StringBuilder yAxisTwo = new StringBuilder();
//FusionChart中的chart
chartHead.append("{'chart':{'caption':'2014年销售水平分布','xaxisname':'月份','yaxisname':'销量','showvalues':'0'},'categories':[{'category':[");
for(int i=1;i<=12;i++)
{
xAxis.append("{'label':'").append(i).append("月'},");
}
yAxisOne.append("'dataset':[{'seriesname':'苹果','data':[");
yAxisTwo.append("{'seriesname':'橘子','parentyaxis':'S','data':[");
for(int j=1;j<=12;j++)
{
yAxisOne.append("{'value':'").append(j*100).append("'},");
yAxisTwo.append("{'value':'").append(j*200).append("'},");
}
chartHead.append(xAxis.toString().substring(0, xAxis.toString().length()-1))
.append("]}],")
.append(yAxisOne.toString().substring(0, yAxisOne.length()-1))
.append("]},")
.append(yAxisTwo.toString().substring(0, yAxisTwo.length()-1))
.append("]}]}");
JSONObject jsonobject = JSONObject.fromObject(chartHead.toString());
return jsonobject;
}
/**
*
* 方法名:main
* 方法类型:DoubleYaxis
* 参数:@param args
* @return :void
* @throws
*/
public static void main(String[] args)
{
System.out.println("FusionChart多系列图之双轴图:"+buildJson());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询