MFColumnGradient is a simple javaScript class that will adjust the background colors of a table column based on the value compared to the column range, similar to that seen in Excel Conditional Formatting Color Scales.
To implement, simply include the .js file
html
Have a table on your webpage:
A | 65 |
B | 66 |
C | 67 |
D | 68 |
html
then call the following javaScript to tell the class to adjust the background colors from #005500 (lowest) to #00FF00 (highest) values.
js
Resulting in
A | 65 |
B | 66 |
C | 67 |
D | 68 |
By default, the class will read all values in the nth column and will ignore "%" or "," characters to detect the number. If the numbers use "," as the decimal place (and "." as the thousands separator), then you can adjust the javascript call setDecimalPlaceChar(chr)
to indicate an alternative decimal place character:
js
For row cells that might want to change a color based on something other than that see visible on the cell, you can use the data-cgvalue
attribute to override what is used internal getValue process.
html
To automatically change the color of the foreground of the cells being changed, switching from black to white when the background goes over a 50% darkness, use the doAutoForeground argument:
js
See https://jsfiddle.net for an editable demo.
Also see
articles/Implementing-a-Monaco-Editorsquarearticles/iConnectionTestsquarearticles/javascript-camerasquarearticles/list-editsquarearticles/minifierssquarearticles/opayosquarearticles/table-drag-sortersquarearticles/typewatchsquareprojects/MFCalendarPopupsquareprojects/MFChartColumnsquareprojects/MFColorPickersquareprojects/MFColorPickerBasicsquareprojects/MFColumnGradientsquareprojects/MFFloatawayMsgsquareprojects/MFPanelssquareprojects/MFSelectorsquare
Comments
New Comment