Linuxkey007 / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

Negative values produce missing bar in bar chart in Android 4.2 #256

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Using achartengine-1.0.0 on Android 4.2.  When a bar chart is rendered with 
negative values, the bar isn't shown.  Bars are correctly shown for positive 
values.  Bars with negative values are confirmed to be showing on Android 2.35 
and I'm fairly certain on 4.1 as well.  Believe this to be new since 4.2.

The following simplified code snippet will reproduce the issue:

    private View testBarChartWithNegativeValues()
    {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(Color.BLUE);
        renderer.addSeriesRenderer(r);
        renderer.setOrientation(Orientation.HORIZONTAL);
        SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(0);
        seriesRenderer.setDisplayChartValues(true);

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        CategorySeries series = new CategorySeries("Series 1");
        double[] v = new double[] { 5230, -7300, 9240, 10540, -7900, 9200, 12030, -11200, 9500, 10500, 11600, 13500 };
        int seriesLength = v.length;
        for (int k = 0; k < seriesLength; k++)
        {
            series.add(v[k]);
        }
        dataset.addSeries(series.toXYSeries());
        return ChartFactory.getBarChartView(getActivity(), dataset, renderer, Type.DEFAULT);

    }

Original issue reported on code.google.com by cknight1...@gmail.com on 3 Dec 2012 at 11:39

GoogleCodeExporter commented 9 years ago
Confirmed that this is an issue since 4.2. Working as expected in 4.1.3.

Original comment by cknight1...@gmail.com on 5 Dec 2012 at 9:08

GoogleCodeExporter commented 9 years ago
Does it work with a range bar chart?

Original comment by dandrome...@gmail.com on 8 Jan 2013 at 4:29

GoogleCodeExporter commented 9 years ago
Range bar chart is OK.  See also attached screenshots showing the missing bars 
in the bar chart and the correct bars in the range chart. (Ignore the first 
range bar in the range_chart.png which only has one value).

Original comment by cknight1...@gmail.com on 8 Jan 2013 at 9:55

Attachments:

GoogleCodeExporter commented 9 years ago
I have just tried it on an Android 4.2 platform and it worked fine.

Original comment by dandrome...@gmail.com on 12 Jan 2013 at 9:13

GoogleCodeExporter commented 9 years ago
Further info on this.  If I have android:targetSdkVersion="17" specified in my 
AndroidManifest.xml file then I see the above behaviour, as will setting the 
version to 14, 15 or 16.  If I remove the targetSdkVersion entirely, or set it 
to version 13 or below, then I correctly see the negative bars.  If I 
understand this correctly, this suggests that a compatibility mode is allowing 
the negative bars to be shown.  Would you agree that this, therefore, is still 
an issue?

Original comment by cknight1...@gmail.com on 13 Jan 2013 at 10:55

GoogleCodeExporter commented 9 years ago

Original comment by dandrome...@gmail.com on 14 Jan 2013 at 7:06

GoogleCodeExporter commented 9 years ago
I have tried that and I still see the negative bar charts. There must be 
something else.

Original comment by dandrome...@gmail.com on 14 Jan 2013 at 3:38

GoogleCodeExporter commented 9 years ago

Original comment by dandrome...@gmail.com on 14 Jan 2013 at 6:42

GoogleCodeExporter commented 9 years ago
hmm, ok, thanks for looking at it anyway.  The only other difference I can 
think of is that I'm using the Google API runtimes, but I'd be surprised if 
that was the issue.

Original comment by cknight1...@gmail.com on 14 Jan 2013 at 9:37

GoogleCodeExporter commented 9 years ago
I have also noticed this issue in an app I'm making. My Verizon GS3 is running 
CM 10.1 and negative values are not being shown, but on my transformer pad 
infinity running 4.1.1, they are showing properly. Also tested on my Mom's 
stock Verizon GS3 which is 4.1 and it also works properly. Have you found any 
more info on this issue?

Original comment by and...@andrewwebber.me on 30 Jan 2013 at 12:06

GoogleCodeExporter commented 9 years ago
No, sorry.  Temporary fix for me is backing off to targetSdkVersion of 13.

Original comment by cknight1...@gmail.com on 30 Jan 2013 at 11:22

GoogleCodeExporter commented 9 years ago
Thanks. That's not an option for me as we're specifically making our app for 
4.0+ so I guess I'll just use the RangeBarChart.

Original comment by and...@andrewwebber.me on 5 Feb 2013 at 8:09

GoogleCodeExporter commented 9 years ago
I Also see no Bar with a negative value INCLUDING the Rangbar. I'm using a 
nexus phone with Android 4.2.2. Same Problem on a Nexus 10 (also with 4.2.2).

Positive Bars are shown, negative bars not. 

Manifest Settings are:
android:minSdkVersion="8"
android:targetSdkVersion="17"

Original comment by zink.joc...@googlemail.com on 29 Mar 2013 at 11:55

GoogleCodeExporter commented 9 years ago
We fixed it. The problem is that Android 4.2 will not draw the bars from bottom 
to top. Here is the fix:

private void drawBar(Canvas canvas, float xMin, float yMin, float xMax, float 
yMax, int scale,
      int seriesIndex, Paint paint) {

    // Fix negative bars
    float temp;
    if (xMin > xMax)
    {
      temp = xMin;
      xMin = xMax;
      xMax = temp;
    }
    if (yMin > yMax)
    {
      temp = yMin;
      yMin = yMax;
      yMax = temp;
    }

...

Original comment by batssha...@gmail.com on 17 Apr 2013 at 2:44

GoogleCodeExporter commented 9 years ago
Excellent fix. Thanks a lot!

Original comment by dandrome...@gmail.com on 7 Jun 2013 at 8:47

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Is it fixed in the libary or must i change the scale min max.

Thanks

Original comment by slimfast...@gmail.com on 15 Oct 2013 at 6:02

GoogleCodeExporter commented 9 years ago
Hello.
  This problem is exists in 1.1.0 version of library.
  How i can fix it ? (complile source by myself ? that is only way ?)

Thanks

Original comment by eugene.d...@gmail.com on 5 Nov 2013 at 10:02

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
unfortunately this problem still occurs v1.1.0.

i solve this problem by changing targetSdk like below:
<uses-sdk
            android:targetSdkVersion="13"
            android:minSdkVersion="10"
/>

Original comment by turedi.gokhan@gmail.com on 3 Jul 2014 at 6:56

GoogleCodeExporter commented 9 years ago
same problem,this work for me
https://repository-achartengine.forge.cloudbees.com/snapshot/org/achartengine/ac
hartengine/1.2.0/

Original comment by rotemav2...@gmail.com on 23 Nov 2014 at 6:25