Skip to content

Commit 3ad20ba

Browse files
ChartJS: manual addition of data changes color for existing values
1 parent bce058a commit 3ad20ba

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

classes/Visualizer/Module/Utility.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,12 @@ private static function set_defaults_chartjs( $chart, $post_status ) {
214214
// fall through.
215215
case 'bar':
216216
for ( $i = 0; $i < $max; $i++ ) {
217-
$colors = self::get_random_color();
218-
$attributes[] = array( 'backgroundColor' => $colors[0], 'hoverBackgroundColor' => $colors[1] );
217+
if ( isset( $settings[ $name ][ $i ]['backgroundColor'] ) && ! empty( $settings[ $name ][ $i ]['backgroundColor'] ) ) {
218+
$attributes[] = array( 'backgroundColor' => $settings[ $name ][ $i ]['backgroundColor'], 'hoverBackgroundColor' => $settings[ $name ][ $i ]['hoverBackgroundColor'] );
219+
} else {
220+
$colors = self::get_random_color();
221+
$attributes[] = array( 'backgroundColor' => $colors[0], 'hoverBackgroundColor' => $colors[1] );
222+
}
219223
}
220224
break;
221225
case 'radar':
@@ -224,8 +228,12 @@ private static function set_defaults_chartjs( $chart, $post_status ) {
224228
// fall through.
225229
case 'area':
226230
for ( $i = 0; $i < $max; $i++ ) {
227-
$colors = self::get_random_color();
228-
$attributes[] = array( 'borderColor' => $colors[0] );
231+
if ( isset( $settings[ $name ][ $i ]['borderColor'] ) && ! empty( $settings[ $name ][ $i ]['borderColor'] ) ) {
232+
$attributes[] = array( 'borderColor' => $settings[ $name ][ $i ]['borderColor'] );
233+
} else {
234+
$colors = self::get_random_color();
235+
$attributes[] = array( 'borderColor' => $colors[0] );
236+
}
229237
}
230238
break;
231239
}

0 commit comments

Comments
 (0)