Afree图表:如何在缩放时增加X轴值(间隙或域范围)

时间:2014-06-25 11:21:39

标签: android jfreechart

任何人都可以帮助我进行缩放! 在进行水平缩放时,我想增加并显示间隙或范围。

https://dl.dropboxusercontent.com/u/184003479/actual.png

现在范围是附加链接是10,12,14,16 ...而缩放它应显示为10,11,12,13,... 如何在缩放时增加此域范围。请指导我。

1 个答案:

答案 0 :(得分:1)

protected static int gapValue; //两个日期之间的差距

private void zoom(PointF source,double startDistance,double endDistance){

    Plot plot = this.chart.getPlot();
    PlotRenderingInfo info = this.info.getPlotInfo();

    if (plot instanceof Zoomable) {
        float scaleDistance = (float) (startDistance / endDistance);
    //for maintaining the limit of zooming range  horizontally
        if (this.mScale * scaleDistance <= 1.0f
                && this.mScale * scaleDistance > 0.1f) {
            this.mScale *= scaleDistance;
            Zoomable z = (Zoomable) plot;
            z.zoomDomainAxes(scaleDistance, info, source, false);

            int sealValue = (int) (gapValue * this.mScale);
            // gap shoud be greater than zero
            if (sealValue == 0)
                sealValue = 1;
        // To re-render the graph dates in domain axis
            ((DateAxis) this.getChart().getXYPlot().getDomainAxis())
                    .setTickUnit(new DateTickUnit(DateTickUnitType.DAY,
                            sealValue, new SimpleDateFormat("MM/dd")));

        }
    }

    // repaint
    invalidate();