Search code examples
androidjfreechart

Afree chart : How to increase X axis values(gap or domain range) while zooming


Can anyone help me on below zooming! While doing horizontal zoom, I would like to increase and display the gap or range.

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

Now the range is on attached link is 10,12,14,16... while zooming it should display as 10,11,12,13,... How I can increase this domain range while zooming. Please guide me.


Solution

  • protected static int gapValue; //gap between two dates

    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();