Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class BarChart extends AbstractChart<BarChartProps, BarChartState> {
y={((baseHeight - barHeight) / 4) * 3 + paddingTop}
width={barWidth}
height={2}
fill={this.props.chartConfig.color(0.6)}
fill={this.props.chartConfig.color(0.6, i)}
/>
);
});
Expand Down Expand Up @@ -205,7 +205,7 @@ class BarChart extends AbstractChart<BarChartProps, BarChartState> {

}
y={((baseHeight - barHeight) / 4) * 3 + paddingTop - 1}
fill={this.props.chartConfig.color(0.6)}
fill={this.props.chartConfig.color(0.6, i)}
fontSize="12"
textAnchor="middle"
>
Expand Down
4 changes: 2 additions & 2 deletions src/HelperTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Dataset {
data: number[];

/** A function returning the color of the stroke given an input opacity value. */
color?: (opacity: number) => string;
color?: (opacity: number, index: number) => string;

/** A function returning array of the colors of the stroke given an input opacity value for each data value. */
colors?: Array<(opacity: number) => string>;
Expand Down Expand Up @@ -90,7 +90,7 @@ export interface ChartConfig {
/**
* Defines the base color function that is used to calculate colors of labels and sectors used in a chart
*/
color?: (opacity: number, index?: number) => string;
color?: (opacity: number, index: number) => string;
/**
* Defines the function that is used to calculate the color of the labels used in a chart.
*/
Expand Down
12 changes: 6 additions & 6 deletions src/line-chart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ class LineChart extends AbstractChart<LineChartProps, LineChartState> {
scrollableDotHorizontalOffset: new Animated.Value(0)
};

getColor = (dataset: Dataset, opacity: number) => {
return (dataset.color || this.props.chartConfig.color)(opacity);
getColor = (dataset: Dataset, opacity: number, index: number) => {
return (dataset.color || this.props.chartConfig.color)(opacity, index);
};

getStrokeWidth = (dataset: Dataset) => {
Expand Down Expand Up @@ -316,7 +316,7 @@ class LineChart extends AbstractChart<LineChartProps, LineChartState> {
fill={
typeof getDotColor === "function"
? getDotColor(x, i)
: this.getColor(dataset, 0.9)
: this.getColor(dataset, 0.9, i)
}
onPress={onPress}
{...this.getPropsForDots(x, i)}
Expand Down Expand Up @@ -637,7 +637,7 @@ class LineChart extends AbstractChart<LineChartProps, LineChartState> {
strokeLinejoin={linejoinType}
points={points.join(" ")}
fill="none"
stroke={this.getColor(dataset, 0.2)}
stroke={this.getColor(dataset, 0.2, index)}
strokeWidth={this.getStrokeWidth(dataset)}
strokeDasharray={dataset.strokeDashArray}
strokeDashoffset={dataset.strokeDashOffset}
Expand Down Expand Up @@ -725,7 +725,7 @@ class LineChart extends AbstractChart<LineChartProps, LineChartState> {
key={index}
d={result}
fill="none"
stroke={this.getColor(dataset, 0.2)}
stroke={this.getColor(dataset, 0.2, index)}
strokeWidth={this.getStrokeWidth(dataset)}
strokeDasharray={dataset.strokeDashArray}
strokeDashoffset={dataset.strokeDashOffset}
Expand Down Expand Up @@ -782,7 +782,7 @@ class LineChart extends AbstractChart<LineChartProps, LineChartState> {
<G key={Math.random()}>
<LegendItem
index={i}
iconColor={this.getColor(datasets[i], 0.9)}
iconColor={this.getColor(datasets[i], 0.9, i)}
baseLegendItemX={baseLegendItemX}
legendText={legendItem}
labelProps={{ ...this.getPropsForLabels() }}
Expand Down