Announcement

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

    How to set the Legend color of choice for a specific data type.

    ****How to set Legend color of choice for a specific Legends type.***


    1. Smart GWT version:-
    v9.0p_2013-08-25/PowerEdition Deployment (built 2013-08-25)

    2. Problem statement:
    I want the color of city Type-"Country" to be Red, "Town" as Green and "Urban" as Blue and so on. I can have several records having one of these types as either Country or Town or Urban.

    In the attached sample code only two legends are there Town(Red) and Country(Green). The COLORS array contains {Red,Green}. The red color ties up with the legend type (Country or Town) whichever comes first in the Bar data records. The legend color ties up with the "type" as and when the city Type comes in the Bar data records.
    If the first record contains type as "Country" then the Red color legend is for "Country" type and if the first record contains type as "Town" then the Red color legend is for "Town" type .

    How can I set the specific Legend color for a specific city Type irrespective of the order in which the city Type is present in the Bar Data records?
    Attached Files
    Last edited by mchoudhary; 9 Sep 2013, 01:30. Reason: For better clarity of Question

    #2
    You can either:

    1. set facetValues explicitly on the "city" Facet so you aren't dependent on the data order

    OR

    2. make the data order consistent by sorting the data before providing it to the FacetChart

    Comment


      #3
      How can I set the specific Legend color for a specific city Type irrespective of the

      Option 1: Do you mean that I should mention the Type "Country" and "Town" explicitly on the city facet. Can you please explain with sample line of code.

      Although, it is not possible to mention the Type explicitly with the Facet, as it is dynamic data coming from DB.

      Option 2: The data order can not be consistent because the Type would be a DB column which has different values such as "Country", "Town", "Urban" etc. with its respective specific color code. We would not be able to identify which record has what Type value?

      But we have specific color code for each Type.

      So it won't be feasible to know the "Type" data order even after sorting, as sorting will be on some other Numeric data column.

      Comment


        #4
        This request doesn't make sense now. You asked for a way to control which colors are applied, and we told you that can control it by providing the facetValues or data in the order you want the colors applied.

        But you've said you don't know the order - well that would also mean you don't know what colors should be applied!!

        So you'll need to solve that on your own, then use the techniques we recommended.

        Comment


          #5
          I have fixed this issue using java code.

          Comment


            #6
            Team,

            We are currently using:-
            BuildDate Wed Mar 05 15:52:00 IST 2014
            Version 4.1p
            SCVersionNumber v9.1p_2014-03-05

            We have used the solution you have given above -
            You can either:

            1. set facetValues explicitly on the "city" Facet so you aren't dependent on the data order

            But our problem is that it is working fine on bar charts and other charts like area charts but not working ONLY for Scatter charts.

            Is it not possible with the scatter charts or there is something wrong with how we have set things?

            This is how I have set facets :-
            Code:
              Facet field = new Facet();
                    field.setId(colorSeriesMetric);
                   orderLegend(portlet, chartProp, field);
            	           // Values facets.
                    Facet groupingFacet = new Facet();
                    groupingFacet.setValues(new FacetValue(yMetric), new FacetValue(xMetric));
                    groupingFacet.setInlinedValues(true);
                    groupingFacet.setId("metric");
                    setFacets(groupingFacet , field);
                    setValueProperty(yMetric);
                    setValueTitle(yMetricTitle);
            And how i have set facet Values:-
            Code:
            	 protected void orderLegend(final ChartsDataToolsPortlet portlet, Record[] chartProp, Facet metricFacet) {
                    if (chartProp[0].getAttributeAsString("LEGEND_DEFAULT_VISIBILITY").equals("1") && portlet.getDrilledLegendColor() == null) {
                   
                        List<String> colorValues = new ArrayList<String>(portlet.getChartConfigurationsObject().getAttrColor().keySet());
                        FacetValue[] facetValue = new FacetValue[colorValues.size()];
                        for (int valueFieldCounter = 0; valueFieldCounter < colorValues.size(); valueFieldCounter++) {
                                        facetValue[valueFieldCounter] = new FacetValue(colorValues.get(valueFieldCounter), colorValues.get(valueFieldCounter));
                        }
                        metricFacet.setValues(facetValue);
                    }
                }

            I have tried to provide minimum code.Please let me know if more information required.

            Comment


              #7
              Sorry, we can't tell much from this code, since we can't see how you attempt to order things, and we can't see what order is used in the data itself.

              If you think this might be a framework issue and not just a bug in one of your helper methods, what you should do is start from the Scatter chart sample code, modify it minimally such that you would expect is to assign colors in a particular way, and show the modified code and explain your expectations for color assignment.

              Comment


                #8
                Thanks for the help.

                We will follow these steps and let you know further.

                Comment

                Working...
                X