小弟正在用JFreeChart实现一个折线图,数据点类似defaultcategorydataset.addValue(0.2D, series1, type1) ; ,
因为所有的数据都是DOUBLE型的,虽然能得到的折线图,但折线图里没有纵坐标刻度。 
而我把值改成5,6这样的整数的时候就能够显示纵坐标刻度。。
这个很尴尬啊,诚心求教PS:由于折线图里有多根折线,哪个函数是设置折线颜色的?

解决方案 »

  1.   

    我之前做过, 我写的这个方法或许能帮你/**
     * 折线图
     * @param sct
     * @param business
     * @return
     */
    public FileInputStream lineHourFlow(double[][] data,String[] rowKeys,String[] columnKeys,String title,String xText,String yText)
    {
            picFileName = Math.random() + ".jpg";

    Resource res = new FileSystemResource(imgPath + picFileName);

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);

    JFreeChart chart = ChartFactory.createLineChart(title,xText,yText, 
    dataset, PlotOrientation.VERTICAL, true, true, false); chart.setTextAntiAlias(false);
    chart.setBackgroundPaint(Color.WHITE);
    // 设置图标题的字体重新设置title
    Font font = new Font("隶书", Font.BOLD, 25);
    TextTitle textTitle = chart.getTitle();
    textTitle.setFont(font);
    chart.setTitle(textTitle);
    // 设置面板字体


    Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 12); chart.setBackgroundPaint(Color.WHITE);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    // x轴 // 分类轴网格是否可见
    categoryplot.setDomainGridlinesVisible(true);
    // y轴 //数据轴网格是否可见
    categoryplot.setRangeGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.WHITE);// 虚线色彩 categoryplot.setDomainGridlinePaint(Color.WHITE);// 虚线色彩 categoryplot.setBackgroundPaint(Color.lightGray);

    // 设置轴和面板之间的距离
    // categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
     
    CategoryAxis domainAxis = categoryplot.getDomainAxis();
    categoryplot.getRangeAxis().setLabelFont(labelFont);
    domainAxis.setLabelFont(labelFont);// 轴标题
    domainAxis.setTickLabelFont(labelFont);// 轴数值
    // domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 横轴上的
    // Lable
    // 45度倾斜
    // 设置距离图片左端距离
    domainAxis.setLowerMargin(0.0);
    // 设置距离图片右端距离
    domainAxis.setUpperMargin(0.0); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(true); // 获得renderer 注意这里是下嗍造型到lineandshaperenderer!!
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot
            .getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); // series 点(即数据点)可见
    lineandshaperenderer.setBaseLinesVisible(true); // series 点(即数据点)间有连线可见
    lineandshaperenderer.setBaseLegendTextFont(labelFont);

    try {
    FileOutputStream fos_jpg = null;

    fos_jpg = new FileOutputStream(res.getFile().getAbsolutePath());

    ChartUtilities.writeChartAsJPEG(fos_jpg, chart, picWidth, picHeight);

    fos_jpg.close();
    FileInputStream inputStream = (FileInputStream) res.getInputStream();

    return inputStream;

    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    return null;
    }