Skip to content

Commit 5801186

Browse files
author
Robert Crocker
committed
Updated the bar chart colors.
1 parent 8917d36 commit 5801186

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/App.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import PieChart from './charts/PieChart/PieChart';
88
import portfolio from '../data/portfolio.json';
99
import penguins from '../data/penguins.json';
1010
import fruit from '../data/fruit.json';
11+
import skinny_fruit from '../data/skinny_fruit.json';
1112

1213
import { Container } from './styles/componentStyles';
1314

@@ -23,13 +24,14 @@ function App() {
2324
outerRadius={240}
2425
pieLabel={true}
2526
/>
26-
{/*<BarChart
27-
theme="dark"
27+
<BarChart
28+
theme="light"
2829
height="100%"
2930
width="100%"
30-
data={portfolio.slice(5, 13)}
31+
data={skinny_fruit.reverse()}
3132
xKey="date"
3233
yKey="value"
34+
groupBy="fruit"
3335
xAxis="bottom"
3436
yAxis="right"
3537
yGrid={true}
@@ -38,7 +40,7 @@ function App() {
3840
legend={'bottom'}
3941
tooltipVisible={true}
4042
/>
41-
<AreaChart
43+
{/*<AreaChart
4244
theme="dark"
4345
height="100%"
4446
width="100%"

src/charts/BarChart/BarChart.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,13 @@ export default function BarChart({
177177
// Define how the data will drive your design
178178
// ********************
179179

180+
const numberOfKeys = Array.from(keys).length;
180181
const discreteColors =
181-
Array.from(keys).length < 4 ? 3 : Math.min(Array.from(keys).length, 9);
182-
const computedScheme = d3[`${colorScheme}`][discreteColors];
183-
const colorScale = d3.scaleOrdinal(Array.from(computedScheme).reverse());
182+
numberOfKeys < 4 ? 3 : Math.min(Array.from(keys).length, 9);
183+
const computedScheme = Array.from(
184+
d3[`${colorScheme}`][discreteColors]
185+
).reverse();
186+
const colorScale = d3.scaleOrdinal(computedScheme);
184187
colorScale.domain(keys);
185188

186189
// ********************

0 commit comments

Comments
 (0)