Question

I am trying to plot a graph using achartengine. As you can see from the image, it looks quite ugly.I want to , 1. Reduce space between values. I cannot have that much space since I need to add more series to it. 2. I am not plotting any negative values, so why it's showing lines at the bottom. The values displayed at the bottom are -1.I want to eliminate any lines at the bottom. 3. If possible, I want to change the background color of graph from black to some other color. Thanks. Code is included with which I am working.

String see = pull.trim();
           String str = '"' + see + '"';

           int[] intArray = new int[str.length()];
           for(int i=0; i < str.length(); i++){

               intArray[i] = Character.digit(str.charAt(i), 10);

           }


        CategorySeries series = new CategorySeries("My Graph");
        for(int i = 0; i <intArray.length; i++){

          series.add("Bar ", intArray[i]);
        }

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        dataset.addSeries(series.toXYSeries());

        XYSeriesRenderer renderer = new XYSeriesRenderer();
        renderer.setDisplayChartValues(true);
        renderer.setChartValuesSpacing((float) 0.1);
        renderer.setColor(getResources().getColor(R.color.fuchsia));



        XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
        mRenderer.addSeriesRenderer(renderer);
        mRenderer.setChartTitle("My Graph");
        mRenderer.setYTitle("Values");
        mRenderer.setZoomButtonsVisible(true);




        LinearLayout chart_container=(LinearLayout)findViewById(R.id.Chart_layout);

        mChart=(GraphicalView)ChartFactory.getBarChartView(getBaseContext(), dataset, mRenderer, Type.DEFAULT);
        chart_container.addView(mChart);

enter image description here

Était-ce utile?

La solution

I found out that the bottom negative values were showing because there were spaces in my string with which I was plotting graph.So I wrote it this way, Hopefully it helps someone in the future.

String see = pull.replaceAll("\\s+","");  

 int[] intArray = new int[see.length()];
           for(int k=0; k < see.length(); k++){

               intArray[k] = Character.digit(see.charAt(k), 10);

           }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top