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
13 changes: 7 additions & 6 deletions src/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface BarChartProps extends AbstractChartProps {
showValuesOnTopOfBars?: boolean;
withCustomBarColorFromData?: boolean;
flatColor?: boolean;

}

type BarChartState = {};
Expand Down Expand Up @@ -161,8 +161,8 @@ class BarChart extends AbstractChart<BarChartProps, BarChartState> {
{flatColor ? (
<Stop offset="1" stopColor={highOpacityColor} stopOpacity="1" />
) : (
<Stop offset="1" stopColor={lowOpacityColor} stopOpacity="0" />
)}
<Stop offset="1" stopColor={lowOpacityColor} stopOpacity="0" />
)}
</LinearGradient>
);
})}
Expand All @@ -185,7 +185,7 @@ class BarChart extends AbstractChart<BarChartProps, BarChartState> {
const baseHeight = this.calcBaseHeight(data, height);

const renderLabel = (value: number) => {
if(this.props.chartConfig.formatTopBarValue) {
if (this.props.chartConfig.formatTopBarValue) {
return this.props.chartConfig.formatTopBarValue(value)
}
else {
Expand All @@ -195,19 +195,20 @@ class BarChart extends AbstractChart<BarChartProps, BarChartState> {
return data.map((x, i) => {
const barHeight = this.calcHeight(x, data, height);
const barWidth = 32 * this.getBarPercentage();
const propsForTopOfBarLabel = { fontSize: 12, ...this.props.chartConfig.propsForTopLabel } || { fontSize: 12 }
return (
<Text
key={Math.random()}
x={
paddingRight +
(i * (width - paddingRight)) / data.length +
barWidth / 1

}
y={((baseHeight - barHeight) / 4) * 3 + paddingTop - 1}
fill={this.props.chartConfig.color(0.6)}
fontSize="12"
textAnchor="middle"
style={propsForTopOfBarLabel}
>
{renderLabel(data[i])}
</Text>
Expand Down
1 change: 1 addition & 0 deletions src/HelperTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface ChartConfig {
*/
barPercentage?: number;
barRadius?: number;
propsForTopLabels?: TextProps;
/**
* Override styles of the background lines, refer to react-native-svg's Line documentation
*/
Expand Down