0

我正在使用 Achartengine。我正在使用条形图显示一些数据,它显示正常。只有一件事我不能做,那就是让条形的值不超过其他值。

在此处输入图像描述

从图像中可以看出,这些值相互重叠。要么我需要使条更厚,要么我需要将值旋转 45 度。

setBarSpacing 不会改变任何东西。这是我创建条形图的方法:

public BarGraph(double[] thisWeekDoubleArray,double[] lastWeekDoubleArray,double yAxisMax, String yTitle,String chartTitle)
{
    
    setData(thisWeekDoubleArray,lastWeekDoubleArray);
    
    mDataset.addSeries(lastWeek.toXYSeries());
    mDataset.addSeries(thisWeek.toXYSeries());
    
    
    // Customize data set 1
    rendererThisWeek.setColor(Color.RED);
    rendererThisWeek.setPointStyle(PointStyle.SQUARE);
    rendererThisWeek.setFillPoints(true);
    
    rendererThisWeek.setDisplayChartValues(true); 
    rendererThisWeek.setChartValuesTextSize(16);
    rendererThisWeek.setLineWidth(2);
    rendererThisWeek.setChartValuesTextAlign(Align.CENTER);
    //rendererThisWeek.setDisplayChartValuesDistance(4);
    
    // Customize data set 2
    rendererLastWeek.setColor(Color.YELLOW);
    rendererLastWeek.setPointStyle(PointStyle.TRIANGLE);
    rendererLastWeek.setFillPoints(true);
    
    rendererLastWeek.setDisplayChartValues(true); 
    rendererLastWeek.setChartValuesTextSize(16);
    rendererLastWeek.setLineWidth(2);
    rendererLastWeek.setChartValuesTextAlign(Align.CENTER);
    //rendererLastWeek.setDisplayChartValuesDistance(4);
    //rendererLastWeek.setChartValuesTextAlign(Align.CENTER); // Default is center
    
    // Add single renderer to multiple renderer and set some
    // properties for the multiple renderer
    mRenderer.addSeriesRenderer(rendererThisWeek);
    mRenderer.addSeriesRenderer(rendererLastWeek);
    
    mRenderer.setChartTitle(chartTitle);
    mRenderer.setXTitle("Day #");
    mRenderer.setYTitle(yTitle);
    mRenderer.setBarWidth(30);
    mRenderer.setBarSpacing(0.5);
    
    //mRenderer.setZoomEnabled(true);
    //mRenderer.setZoomButtonsVisible(true);
    
    //For applying background
    //mRenderer.setApplyBackgroundColor(true);
    //mRenderer.setBackgroundColor(Color.BLACK);
    //mRenderer.setMarginsColor(Color.BLACK);
    
    mRenderer.setAxisTitleTextSize(20);
    mRenderer.setChartTitleTextSize(28);
    mRenderer.setLabelsTextSize(18);
    mRenderer.setLegendTextSize(18);
    
    // margins - an array containing the margin size values, in this order: top, left, bottom, right
    mRenderer.setMargins(new int[] { 20, 30, 35, 20 });
    
    // Sets the legend text size.
    mRenderer.setLegendTextSize(30);
    mRenderer.setLegendHeight(45);
    //mRenderer.setFitLegend(true);
    
    // This sets how many x labels should be visible.
    // Since I make my own labels I have to set this to 0
    mRenderer.setXLabels(0);
    // Adds the labels for the x axis.
    // This is the days.
    mRenderer.addXTextLabel(1, "-6");
    mRenderer.addXTextLabel(2, "-5");
    mRenderer.addXTextLabel(3, "-4");
    mRenderer.addXTextLabel(4, "-3");
    mRenderer.addXTextLabel(5, "-2");
    mRenderer.addXTextLabel(6, "-1");
    mRenderer.addXTextLabel(7, "0");
    
    mRenderer.setXLabelsPadding(0.8f);
    
    // Aligns the y label to the left of y = 0
    mRenderer.setYLabelsAlign(Align.LEFT);
    
    // Sets the max and min values of the x and y axis.
    // This changes how the chart is displayed the first time.
    // This should be a bit higher and lower than the highest and lowest
    // values that will be displayed.
    mRenderer.setXAxisMin(0);
    mRenderer.setXAxisMax(8);
    /*
    mRenderer.setBarSpacing(5.0);
    */
    
    

    mRenderer.setYAxisMin(0);
    mRenderer.setYAxisMax(yAxisMax);
    

    
    //mRenderer.setClickEnabled(true);
    /*
    mRenderer.setFitLegend(true);
    mRenderer.setZoomRate(0.2f); 
    mRenderer.setMargins(new int[] { 70, 50, 50, 30 });
    mRenderer.setBarSpacing(0.2f);
    */
    
}

有人知道该怎么做吗?

谢谢

4

0 回答 0