Android - problems with artanging graphics

I use achartengine to draw my chart in an Android application and has 2 problems with the histogram.

1: values ​​in the top line do not align the center

2: the bandwidth is too small when only 1 bar in the chart

enter image description here

enter image description here

Here is my code for setting the schedule

    GraphicalView mChart;
    // Creating an  XYSeries for Income
    XYSeries incomeSeries = new XYSeries("\n" + note);
    // Adding data to Series
    // Arraylist<String> althongtin include input data (some numbers character, eg: {125, 4356, 50000})
    for(int i=0;i<althongtin.size();i++){
        incomeSeries.add(i, Double.parseDouble(althongtin.get(i)));
    }

    // Creating a dataset to hold each series
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    // Adding Income Series to the dataset
    dataset.addSeries(incomeSeries);
    XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();

    incomeRenderer.setColor(color);
    incomeRenderer.setChartValuesTextSize(20);
    incomeRenderer.setFillPoints(true);
    incomeRenderer.setDisplayChartValues(true);
    incomeRenderer.setChartValuesTextAlign(Paint.Align.CENTER);

    XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();

    multiRenderer.setXLabels(0);
    multiRenderer.setChartTitle(ten);
    multiRenderer.setXTitle(cotx);
    multiRenderer.setYTitle(coty);
    multiRenderer.setYLabelsAlign(Paint.Align.LEFT);
    multiRenderer.setBarSpacing(1);
    multiRenderer.setBarWidth(50);

    multiRenderer.setYAxisMin(0);
    multiRenderer.setYAxisMax(max + (max/10));
    multiRenderer.setXAxisMin(-1);
    multiRenderer.setXAxisMax(althongtin.size() + 1);
    multiRenderer.setLabelsTextSize(15);
    multiRenderer.setLegendTextSize(20);
    multiRenderer.setAxisTitleTextSize(20);
    multiRenderer.setChartTitleTextSize(20);

    multiRenderer.setLabelsColor(Color.BLACK);
    multiRenderer.setAxesColor(Color.BLACK);
    multiRenderer.setApplyBackgroundColor(true);
    multiRenderer.setBackgroundColor(Color.TRANSPARENT);
    multiRenderer.setMarginsColor(Color.argb(0,255,255,255));
    multiRenderer.setXLabelsColor(Color.BLACK);
    multiRenderer.setYLabelsColor(0, Color.BLACK);

    multiRenderer.addSeriesRenderer(incomeRenderer);

    String[] types = new String[] {BarChart.TYPE};

    mChart = (GraphicalView) ChartFactory.getCombinedXYChartView(getBaseContext(), dataset, multiRenderer, types);

    multiRenderer.setClickEnabled(true);
    multiRenderer.setSelectableBuffer(10);

    chartLayout.addView(mChart);

Thanks.

Update: The second problem was fixed by updating to achartengine 1.2.0. Thanks Dan.

+4
source share
2 answers

For the first problem, you can upgrade to nightly build 1.2.0.

For the second: renderer.setBarWidth(widthInPixels);since it is a solution for setting the bandwidth when there is one element in the series.

+1
source

ChartFactory.getBarChartView ChartFactory.getCombinedXYChartIntent?

, .

0

Source: https://habr.com/ru/post/1527635/


All Articles