没人研究Jfreechart么?
N个地方贴问题了,就是没人答.
小弟我要实现在一个jsp页面上画出两个曲线图,每个图都是以时间为x轴,多纵轴.并且要在鼠标指向各个数据点的时候显示其坐标.
写了一个方法
public void drawMoreZheXian(ArrayList TimeSeriesLIst, ArrayList showList,
ArrayList colorList, String[] groupArr,
String[] titleArr, String zmStr,
JspWriter out, int width, int height,
String[] colorArr, int bgcolor) {
CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(zmStr));
if (groupArr != null && groupArr.length > = 1) {
for (int i = 0; i < groupArr.length; i++) {
//String[] numArr = groupArr[i].split( ", ");
//循环把各组值放到 collection中
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries( (TimeSeries) TimeSeriesLIst.get(i));
//生产工具提示信息的ArrayList
ArrayList[] tooltips = new ArrayList[showList.size()];
for (int k = 0; k < showList.size(); k++) {
tooltips[k] = getCurveSeries( (String[]) showList.get(k));
}
////////////////////////井数
NumberAxis rangeAxis1 = new NumberAxis(titleArr[i]);
CustomXYToolTipGenerator ttg1 = new CustomXYToolTipGenerator();
//加入各条曲线的工具提示条
ttg1.addToolTipSeries(tooltips[i]);
//生成曲线的透视层
StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(
StandardXYItemRenderer.SHAPES_AND_LINES,
ttg1, null);
rangeAxis1.setAutoRangeIncludesZero(false);
rangeAxis1.setAutoRangeStickyZero(false);
//设置小数位数
rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
XYPlot subplot1 = new XYPlot(dataset, null, rangeAxis1, renderer1);
subplot1.setBackgroundPaint(new GradientPaint(0, 100,
new Color(0xccccff), 130, 240, new Color(0xeffcd0), true));
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.add(subplot1, 1);
plot.setBackgroundPaint(new Color(bgcolor));
if (colorList != null && colorList.size() > 0) {
renderer1.setSeriesPaint(0, (Color) colorList.get(i));
}
rangeAxis1.setAutoRange(true);
JFreeChart chart = new JFreeChart( " ",
JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(new Color(bgcolor));
plot.setDomainCrosshairVisible(false);
plot.setRangeCrosshairVisible(false);
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1,
new SimpleDateFormat( "MM-dd ")));
XYItemRenderer xyitemrenderer = plot.getRenderer();
if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)
xyitemrenderer;
xylineandshaperenderer.setBaseShapesVisible(true);
xylineandshaperenderer.setBaseShapesFilled(true);
}
FileOutputStream fos_jpg = null;
String[] imgUrl = null;
ChartRenderingInfo info = null;
try {
imgUrl = ImgScgz.getImgUrl();
fos_jpg = new FileOutputStream(imgUrl[0]);
info = new ChartRenderingInfo();
ChartUtilities.writeChartAsJPEG(fos_jpg, 100, chart, width, height, info); //图形的大小
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
fos_jpg.close();
}
catch (Exception e) {}
}
try {
out.print( " <img src= " + imgUrl[1] + " border=0 usemap=#mapName> ");
out.print(ChartUtilities.getImageMap( "mapName ", info));
}
catch (Exception e) {}
}
}
方法getCurveSeries内容
public ArrayList getCurveSeries(String[] str) {
//所对应的工具提示
ArrayList toolTips = new ArrayList();
for (int i = 0; i < str.length; i++) {
toolTips.add(str[i]);
}
return toolTips;
}
然后在jsp中调用两次这个方法,只是传递的参数不一致,但是只能显示前一个图的数据点,后一个死活出不来.貌似还是用的前一个的tooltips,因为有时两边数据一致的时候就能显示.
日志里打出来的数据是又是对的.总之我是晕了,不知道怎么解决!
请教高手是怎么回事?
[解决办法]
用debug试试,可能很多人都不熟悉
[解决办法]
不应该调用两次,应该是一副图,jfreechart好像有做组合图的方法
[解决办法]
帮顶,还没用过Jfreechart