LoadConfigDoc(strChartConfigURL);
// 然后取得用于数据系列的XPath列表
strDummy = GetChildItem(elemItem, "series");
LoadSeries(strDummy);
// 取得用于数据类别的XPath列表
strDummy = GetChildItem(elemItem, "categories");
LoadCategories(strDummy);
// 取得图像的尺寸
// 首先检查strX和strY参数.
// 如果没有参数,从配置文件中读取。
nXSize = new Integer(strX).intValue();
if (nXSize==0)
{
strDummy = GetChildItem(elemItem, "XSize");
nXSize = new Integer(strDummy).intValue();
}
nYSize = new Integer(strY).intValue();
if (nYSize==0)
{
strDummy = GetChildItem(elemItem, "YSize");
nYSize = new Integer(strDummy).intValue();
}
// 开始制图:
DoChart();
// 输出图表
response.setContentType("image/jpeg");
OutputStream out = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(out, chart, nXSize, nYSize);
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
用Java从XML文件中获取业务图表(3)
时间:2010-12-06
代码段2 DoChart函数
private void DoChart()
{
Node nRoot;
Element nElem;
int nType;
String strTitle;
String strCatTitle;
String strValTitle;
String strSTitleList;
nRoot = xmlConfig.getDocumentElement();
nElem = (Element) nRoot;
nType = new Integer(GetChildItem(nElem,"Type")).intValue();
strTitle = GetChildItem(nElem,"Title");
strCatTitle = GetChildItem(nElem,"CatTitle");
strValTitle = GetChildItem(nElem, "ValTitle");
strSTitleList = GetChildItem(nElem, "SeriesTitles");
LoadSeriesTitles(strSTitleList);
// 取得数据并把它导入正确的数据结构
categoryData = createDataset();
// 分析图表类型然后创建适合的图表
switch(nType){
case 0:
{
// 垂直条状图
chart = ChartFactory.createVerticalBarChart
(strTitle, strCatTitle, strValTitle, categoryData, true);
break;
}
case 1:
{
// 饼状图
PieDataset pieData = DatasetUtilities.createPieDataset
(categoryData, 0); chart = ChartFactory.createPieChart
(strTitle, pieData, true);
break;
}
case 2:
{
// 水平条状图
chart = ChartFactory.createHorizontalBarChart
(strTitle, strCatTitle, strValTitle, categoryData, true);
break;
}
case 3:
{
// 线状图
chart = ChartFactory.createLineChart
(strTitle, strCatTitle, strValTitle, categoryData, true);
break;
}
case 4:
{
// 面积图
chart = ChartFactory.createAreaChart
(strTitle, strCatTitle, strValTitle, categoryData, true);
break;
}
case 5:
{
// 3D水平条状图
chart = ChartFactory.createHorizontalBarChart3D
(strTitle, strCatTitle, strValTitle, categoryData, true);
break;
}
case 6:
{
// 3D 饼状图
PieDataset pieData = DatasetUtilities.createPieDataset(categoryData, 0);
chart = ChartFactory.createPie3DChart(strTitle, pieData, true);
break;
}
case 7:
{
// 堆积水平条状图
chart = ChartFactory.createStackedHorizontalBarChart
(strTitle, strCatTitle, strValTitle, categoryData, true);
break;
}
case 8:
{
// 堆积垂直条状图
chart = ChartFactory.createStackedVerticalBarChart
(strTitle, strCatTitle, strValTitle, categoryData, true);
break;
}
case 9:
{
// 3D堆积垂直条状图
chart = ChartFactory.createStackedV
|