Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Problem in BarChart

    Version v9.1p_2014-10-15/Pro Deployment (2014-10-15)

    Hi,

    I've got a problem with BarCharts (stacked) when there are 2 records and one of them has a value 3 and the other value 1. The values are correct but the graphic view is starting at 2.8 instead of 0.

    Code:
    public class TesteSmartGWTEntryPoint implements EntryPoint 
    {
    	private VLayout rootLayout;
    	
    	@Override
    	public void onModuleLoad()
    	{
    		try
    		{
    			rootLayout = new VLayout();
    			rootLayout.setWidth("98,5%");
    			rootLayout.setHeight("97%");
    			RootPanel.get().add(rootLayout);
    			buildLayout();
    		}
    		catch (Exception e)
    		{
    		}
    	}
    
    	private void buildLayout()
    	{
    		HashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
    		map.put("String 1", 3);
    		map.put("String 2", 1);
    		
    		final FacetChart chart = new FacetChart();
    		chart.setFacets(new Facet("entity", " "), new Facet("currentAttribute", "Attribute"));
    		chart.setValueProperty("number");
    		chart.setChartType(ChartType.BAR);
    		
    		chart.setTitle("Bar Chart");
    		chart.setHeight100();
    		chart.setWidth100();
    		chart.setAlign(Alignment.CENTER);
    		chart.setShowDataValues(true);
            
    		List<BarChartRecord> recordList = new ArrayList<BarChartRecord>();
    		for (Map.Entry<String, Integer> cPair : map.entrySet())
    			recordList.add(new BarChartRecord(cPair.getKey(), cPair.getValue()));
    		chart.setData(recordList.toArray(new BarChartRecord[] {}));
    		
    		rootLayout.addMembers(chart);
    	}
    	
    	public class BarChartRecord extends Record 
    	{
    		protected BarChartRecord()
    		{
    			
    		}
    		
    		public BarChartRecord(String name, Integer value)
    		{
    			setAttribute("currentAttribute", name);
    			setAttribute("number", value);
    			setAttribute("entity", " ");
    		}
    	}
    }
    Thank you in advance

    #2
    The data values you are passing to the chart do not include 3. You code actually provides "String 1" as the value for the currentAttribute facet instead of 3, because you pass the key of the first entry of the map to your BarChartRecord helper class, whereas it looks like you actually meant to pass the value.

    Comment


      #3
      The map key is a random name for the serie color, the second argument is the value that will be used as the valueProperty for the chart.

      When I put just two records with values 1 and 3 I expected that the bar chart drawn shows 75% of it in one color and the other 25% in the other (like in pizza charts).

      I've already solved the problem using "setAxisStartValue(0.0)" but I disagree with this behaviour.

      Comment


        #4
        No seriously, try stepping through your code in the debugger, it does not pass the value 3 to the chart at all.

        Comment


          #5
          Yes, I'm passing values 3 and 1 for the two records since:

          Code:
          chart.setValueProperty("number");
          and

          Code:
          setAttribute("number", value);
          The code I provided draws a stacked bar chart. If I right click the chart and choose 'Unstacked' it shows two columns: one going from 0 to 3 and another from 0 to 1. I was expecting that the stacked bar chart would also start at 0. If so, the first record would be represented from 0 to 3 and the other from 3 to 4.

          The problem is that the stacked bar chart has its value axis starting at a number different than zero and then the bar size till 3 is smaller than expected.

          If you run the code and see the chart drawn you will see what i'm talking about.

          Comment


            #6
            Oh, what you seem to be complaining about is that a non-zero axis start value is sometimes chosen. This is controlled by facetChart.minDataSpreadPercent. You generally want to leave this property enabled rather than turn it off entirely via forcing the axisStartValue to 0, see the docs for what it means and how to configure it.

            Comment

            Working...
            X