Grid: different background color (of row) based on valuesGrid - change entire row background color based on values on one column?Build a refined grid based on intersecting lineInteractively select a row/column of a GridDraw grid lines at multiples of kGrid - change entire row background color based on values on one column?Is there a way to exert finer control Dataset Cell Coloration Like in Grid?Equalizing the column widths in the rows below the title row of a gridAlign two Grids in a RowDynamically selecting Rows from a GridHow to substitute curly brackets with round brackets in a grid of listConnect grid with dataset to change grid background

Position representation of spin states and spin operators

How do I keep a running total of data in a column in Excel?

How do I make conditions based on list options?

How does the 'five minute adventuring day' affect class balance?

Avoiding repetition when using the "snprintf idiom" to write text

Do electrons really perform instantaneous quantum leaps?

Is it advisable to inform the CEO about his brother accessing his office?

Where to connect the fuse and why?

Why should I allow multiple IPs on a website for a single session?

What happens if a caster is surprised while casting a spell with a long casting time?

How can an inexperienced GM keep a game fun for experienced players?

Having to constantly redo everything because I don't know how to do it

Calculus, water poured into a cone: Why is the derivative non-linear?

Does friction always oppose motion?

Customs and immigration on a USA-UK-Sweden flight itinerary

Why didn't Caesar move against Sextus Pompey immediately after Munda?

"I am [the / an] owner of a bookstore"?

Checkmate in 1 on a Tangled Board

Is it possible to alias a column based on the result of a select+where?

Does "boire un jus" tend to mean "coffee" or "juice of fruit"?

Hard for me to understand one tip written in "The as-if rule" of cppreference

Rear derailleur got caught in the spokes, what could be a root cause

I agreed to cancel a long-planned vacation (with travel costs) due to project deadlines, but now the timeline has all changed again

How far can gerrymandering go?



Grid: different background color (of row) based on values


Grid - change entire row background color based on values on one column?Build a refined grid based on intersecting lineInteractively select a row/column of a GridDraw grid lines at multiples of kGrid - change entire row background color based on values on one column?Is there a way to exert finer control Dataset Cell Coloration Like in Grid?Equalizing the column widths in the rows below the title row of a gridAlign two Grids in a RowDynamically selecting Rows from a GridHow to substitute curly brackets with round brackets in a grid of listConnect grid with dataset to change grid background













2












$begingroup$


I want to use Grid to tabulate the following list and have the same background color for rows of the same value on column 4.
The actual list is very long.



list=
1, 2, 1, 1, 1, 0, -1, 1, 4.48,
2, -2, -1, -1, -1, 0, 1, -1, 4.48,
3, 2, 1, 1, 1, 0, -1, 1, 4.48,
4, -2, -1, -1, -1, 0, 1, -1, 4.48,
9, -2, -1, 1, -1, 0, 1, 1, 4.48,
10, 2, 1, -1, 1, 0, -1, -1, 4.48,
11, 2, 1, -1, 1, 0, -1, -1, 4.48,
12, -2, -1, 1, -1, 0, 1, 1, 4.48,
5, 0, -1, 0, 1, -2, 1, 0, 5.266,
6, 0, -1, 0, 1, -2, 1, 0, 5.266,
7, 0, 1, 0, -1, 2, -1, 0, 5.266,
8, 0, 1, 0, -1, 2, -1, 0, 5.266,
5, 1, -4, 0, 2, -3, 1, 0, 5.6323,
6, 1, -4, 0, 2, -3, 1, 0, 5.6323,
7, -1, 4, 0, -2, 3, -1, 0, 5.6323,
8, -1, 4, 0, -2, 3, -1, 0, 5.6323


I found a solution to a similar question here. I wonder how can I build the colorrules elegantly. Thanks.










share|improve this question









$endgroup$
















    2












    $begingroup$


    I want to use Grid to tabulate the following list and have the same background color for rows of the same value on column 4.
    The actual list is very long.



    list=
    1, 2, 1, 1, 1, 0, -1, 1, 4.48,
    2, -2, -1, -1, -1, 0, 1, -1, 4.48,
    3, 2, 1, 1, 1, 0, -1, 1, 4.48,
    4, -2, -1, -1, -1, 0, 1, -1, 4.48,
    9, -2, -1, 1, -1, 0, 1, 1, 4.48,
    10, 2, 1, -1, 1, 0, -1, -1, 4.48,
    11, 2, 1, -1, 1, 0, -1, -1, 4.48,
    12, -2, -1, 1, -1, 0, 1, 1, 4.48,
    5, 0, -1, 0, 1, -2, 1, 0, 5.266,
    6, 0, -1, 0, 1, -2, 1, 0, 5.266,
    7, 0, 1, 0, -1, 2, -1, 0, 5.266,
    8, 0, 1, 0, -1, 2, -1, 0, 5.266,
    5, 1, -4, 0, 2, -3, 1, 0, 5.6323,
    6, 1, -4, 0, 2, -3, 1, 0, 5.6323,
    7, -1, 4, 0, -2, 3, -1, 0, 5.6323,
    8, -1, 4, 0, -2, 3, -1, 0, 5.6323


    I found a solution to a similar question here. I wonder how can I build the colorrules elegantly. Thanks.










    share|improve this question









    $endgroup$














      2












      2








      2





      $begingroup$


      I want to use Grid to tabulate the following list and have the same background color for rows of the same value on column 4.
      The actual list is very long.



      list=
      1, 2, 1, 1, 1, 0, -1, 1, 4.48,
      2, -2, -1, -1, -1, 0, 1, -1, 4.48,
      3, 2, 1, 1, 1, 0, -1, 1, 4.48,
      4, -2, -1, -1, -1, 0, 1, -1, 4.48,
      9, -2, -1, 1, -1, 0, 1, 1, 4.48,
      10, 2, 1, -1, 1, 0, -1, -1, 4.48,
      11, 2, 1, -1, 1, 0, -1, -1, 4.48,
      12, -2, -1, 1, -1, 0, 1, 1, 4.48,
      5, 0, -1, 0, 1, -2, 1, 0, 5.266,
      6, 0, -1, 0, 1, -2, 1, 0, 5.266,
      7, 0, 1, 0, -1, 2, -1, 0, 5.266,
      8, 0, 1, 0, -1, 2, -1, 0, 5.266,
      5, 1, -4, 0, 2, -3, 1, 0, 5.6323,
      6, 1, -4, 0, 2, -3, 1, 0, 5.6323,
      7, -1, 4, 0, -2, 3, -1, 0, 5.6323,
      8, -1, 4, 0, -2, 3, -1, 0, 5.6323


      I found a solution to a similar question here. I wonder how can I build the colorrules elegantly. Thanks.










      share|improve this question









      $endgroup$




      I want to use Grid to tabulate the following list and have the same background color for rows of the same value on column 4.
      The actual list is very long.



      list=
      1, 2, 1, 1, 1, 0, -1, 1, 4.48,
      2, -2, -1, -1, -1, 0, 1, -1, 4.48,
      3, 2, 1, 1, 1, 0, -1, 1, 4.48,
      4, -2, -1, -1, -1, 0, 1, -1, 4.48,
      9, -2, -1, 1, -1, 0, 1, 1, 4.48,
      10, 2, 1, -1, 1, 0, -1, -1, 4.48,
      11, 2, 1, -1, 1, 0, -1, -1, 4.48,
      12, -2, -1, 1, -1, 0, 1, 1, 4.48,
      5, 0, -1, 0, 1, -2, 1, 0, 5.266,
      6, 0, -1, 0, 1, -2, 1, 0, 5.266,
      7, 0, 1, 0, -1, 2, -1, 0, 5.266,
      8, 0, 1, 0, -1, 2, -1, 0, 5.266,
      5, 1, -4, 0, 2, -3, 1, 0, 5.6323,
      6, 1, -4, 0, 2, -3, 1, 0, 5.6323,
      7, -1, 4, 0, -2, 3, -1, 0, 5.6323,
      8, -1, 4, 0, -2, 3, -1, 0, 5.6323


      I found a solution to a similar question here. I wonder how can I build the colorrules elegantly. Thanks.







      grid-layouts






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      Bemtevi77Bemtevi77

      897 bronze badges




      897 bronze badges




















          3 Answers
          3






          active

          oldest

          votes


















          3












          $begingroup$

          Here is a solution with Item[...] :



          itemRules = 
          With[color = RandomColor[],
          (x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];

          Grid[list /. itemRules, Dividers -> All]


          enter image description here






          share|improve this answer











          $endgroup$




















            2












            $begingroup$

            sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
            colors = LightYellow, LightOrange, LightBlue;
            colorrules =
            Flatten@Table[
            Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];

            Grid[list, Frame -> All, Background -> None, colorrules]


            enter image description here






            share|improve this answer









            $endgroup$




















              1












              $begingroup$

              Using Association and Lookup to specify row backgrounds:



              keys = Union @ list[[All, -1]];
              colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
              backgroundColors = AssociationThread[keys, colors];

              Legended[Grid[list, Frame -> All,
              Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
              SwatchLegend[colors, keys]]


              enter image description here






              share|improve this answer









              $endgroup$















                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "387"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201189%2fgrid-different-background-color-of-row-based-on-values%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                3












                $begingroup$

                Here is a solution with Item[...] :



                itemRules = 
                With[color = RandomColor[],
                (x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];

                Grid[list /. itemRules, Dividers -> All]


                enter image description here






                share|improve this answer











                $endgroup$

















                  3












                  $begingroup$

                  Here is a solution with Item[...] :



                  itemRules = 
                  With[color = RandomColor[],
                  (x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];

                  Grid[list /. itemRules, Dividers -> All]


                  enter image description here






                  share|improve this answer











                  $endgroup$















                    3












                    3








                    3





                    $begingroup$

                    Here is a solution with Item[...] :



                    itemRules = 
                    With[color = RandomColor[],
                    (x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];

                    Grid[list /. itemRules, Dividers -> All]


                    enter image description here






                    share|improve this answer











                    $endgroup$



                    Here is a solution with Item[...] :



                    itemRules = 
                    With[color = RandomColor[],
                    (x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];

                    Grid[list /. itemRules, Dividers -> All]


                    enter image description here







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 7 hours ago

























                    answered 8 hours ago









                    andre314andre314

                    12.6k1 gold badge24 silver badges53 bronze badges




                    12.6k1 gold badge24 silver badges53 bronze badges





















                        2












                        $begingroup$

                        sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
                        colors = LightYellow, LightOrange, LightBlue;
                        colorrules =
                        Flatten@Table[
                        Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];

                        Grid[list, Frame -> All, Background -> None, colorrules]


                        enter image description here






                        share|improve this answer









                        $endgroup$

















                          2












                          $begingroup$

                          sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
                          colors = LightYellow, LightOrange, LightBlue;
                          colorrules =
                          Flatten@Table[
                          Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];

                          Grid[list, Frame -> All, Background -> None, colorrules]


                          enter image description here






                          share|improve this answer









                          $endgroup$















                            2












                            2








                            2





                            $begingroup$

                            sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
                            colors = LightYellow, LightOrange, LightBlue;
                            colorrules =
                            Flatten@Table[
                            Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];

                            Grid[list, Frame -> All, Background -> None, colorrules]


                            enter image description here






                            share|improve this answer









                            $endgroup$



                            sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
                            colors = LightYellow, LightOrange, LightBlue;
                            colorrules =
                            Flatten@Table[
                            Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];

                            Grid[list, Frame -> All, Background -> None, colorrules]


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 7 hours ago









                            MelaGoMelaGo

                            1,8561 gold badge1 silver badge7 bronze badges




                            1,8561 gold badge1 silver badge7 bronze badges





















                                1












                                $begingroup$

                                Using Association and Lookup to specify row backgrounds:



                                keys = Union @ list[[All, -1]];
                                colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
                                backgroundColors = AssociationThread[keys, colors];

                                Legended[Grid[list, Frame -> All,
                                Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
                                SwatchLegend[colors, keys]]


                                enter image description here






                                share|improve this answer









                                $endgroup$

















                                  1












                                  $begingroup$

                                  Using Association and Lookup to specify row backgrounds:



                                  keys = Union @ list[[All, -1]];
                                  colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
                                  backgroundColors = AssociationThread[keys, colors];

                                  Legended[Grid[list, Frame -> All,
                                  Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
                                  SwatchLegend[colors, keys]]


                                  enter image description here






                                  share|improve this answer









                                  $endgroup$















                                    1












                                    1








                                    1





                                    $begingroup$

                                    Using Association and Lookup to specify row backgrounds:



                                    keys = Union @ list[[All, -1]];
                                    colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
                                    backgroundColors = AssociationThread[keys, colors];

                                    Legended[Grid[list, Frame -> All,
                                    Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
                                    SwatchLegend[colors, keys]]


                                    enter image description here






                                    share|improve this answer









                                    $endgroup$



                                    Using Association and Lookup to specify row backgrounds:



                                    keys = Union @ list[[All, -1]];
                                    colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
                                    backgroundColors = AssociationThread[keys, colors];

                                    Legended[Grid[list, Frame -> All,
                                    Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
                                    SwatchLegend[colors, keys]]


                                    enter image description here







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 4 hours ago









                                    kglrkglr

                                    201k10 gold badges230 silver badges459 bronze badges




                                    201k10 gold badges230 silver badges459 bronze badges



























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Mathematica Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        Use MathJax to format equations. MathJax reference.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201189%2fgrid-different-background-color-of-row-based-on-values%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

                                        Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

                                        Кастелфранко ди Сопра Становништво Референце Спољашње везе Мени за навигацију43°37′18″ СГШ; 11°33′32″ ИГД / 43.62156° СГШ; 11.55885° ИГД / 43.62156; 11.5588543°37′18″ СГШ; 11°33′32″ ИГД / 43.62156° СГШ; 11.55885° ИГД / 43.62156; 11.558853179688„The GeoNames geographical database”„Istituto Nazionale di Statistica”проширитиууWorldCat156923403n850174324558639-1cb14643287r(подаци)