Announcement

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

    FacetChart.getDataColor(int index) never called

    Hi,

    I'm currently using SmartGwt Power 4.1 (v9.1p_2014-08-11).

    I'm trying to define colors displayed in charts by overriding FacetChart.getDataColor(int index) so I can assign a fix color to a known facet value.

    Problem is getDataColor is never called.

    Here is a simple test case:
    Code:
    FacetChart test = new FacetChart() {
            @Override
            public String getDataColor(int index) {
                return "#abcdef";
         }
    };
    test.setChartType(ChartType.PIE);
    test.setFacets(new Facet("test"));
    test.setValueProperty("value");
    Record r = new Record();
    r.setAttribute("value",10);
    r.setAttribute("test", "cat1");
    	    
    test.setData(new Record[] {r});
    test.setSize("300", "300");
    test.draw();
    Thanks in advance for your help
    Antoine Galataud

    #2
    This is not set up as an override point. Methods that can be validly overridden are marked in the documentation with the text "This is an override point".

    If you can let us know what you were trying to do, we can suggest another approach.

    Comment


      #3
      Javadoc of the method:

      "Get a color from the dataColors Array
      Override to provide a dynamic color generation scheme."

      I want to define and fix the color associated with facet values, for instance "cat1" will always have blue, "cat2" red, ...
      For now i can chose colors with setDataColors, but not associate them with specific facet value.

      Comment


        #4
        Despite the poor phrasing in that javadoc, which we'll correct, again the special marker phrase is not present, so this is not a valid override point in SmartGWT.

        You can look to achieve your color matching goal by providing a dataColors array at chart creation time that matches the facets you provide.

        Comment


          #5
          I've tried using dataColors already; problem with that is I can't associate a color with a specific facet value.
          If I have 3 possible values (cat1, cat2, cat3), but the record set returned isn't always the same (e.g. may return cat1 and cat2 only), how can I fix color for each value? (e.g. cat1 always red, cat2 blue, ...)

          Comment


            #6
            Correct, in order to use dataColors to color facetValues correctly, you will need to know (or detect) the order in which facetValues are specified, or the order in which they appear in your data.

            Comment


              #7
              I've tried to reset data colors used by chart when data is received, by creating a String[] of colors with only colors needed for the data set; that would let me define X colors, but only use Y of them so I'd still have the same color for value i even if i-1 is not in the result set.

              Unfortunately, the API is not able to handle such dynamic change:

              Code:
              java.lang.IllegalStateException: Cannot change configuration property 'dataColors' to [Ljava.lang.String;@4cbe2b36 now that component isc_ChartGadget_AdvancedFacetChart_1 has been created.
              Any idea?

              Comment


                #8
                Right, as the error message says, define the dataColors before drawing the chart.

                There's no point in first allowing the chart to draw with wrong colors and then calling setDataColors.

                Comment


                  #9
                  Right, but i was hoping I could avoid recreating the chart each time a user asks for a refresh. Just issuing a request, setting data on the chart and resetting colors from the dataset.
                  Now my only solution is to recreate the chart each time. Not ideal and probably has a cost (we have dashboards with several of them)
                  Thx anyway

                  Comment


                    #10
                    If the chart has totally unrelated data and even colors, not much could be saved by keeping the same chart - every visual aspect of the chart is re-created.

                    Comment

                    Working...
                    X