diff --git a/src/AbstractChart.tsx b/src/AbstractChart.tsx index 4f7b124f..f0a2f718 100644 --- a/src/AbstractChart.tsx +++ b/src/AbstractChart.tsx @@ -32,6 +32,7 @@ export interface AbstractChartConfig extends ChartConfig { formatXLabel?: (xLabel: string) => string; verticalLabelsHeightPercentage?: number; formatTopBarValue?: (topBarValue: number) => string | number; + yAxisPosition?: 'left' | 'right'; } export type AbstractChartState = {}; @@ -140,7 +141,7 @@ class AbstractChart< height, paddingTop, paddingRight, - verticalLabelsHeightPercentage = DEFAULT_X_LABELS_HEIGHT_PERCENTAGE + verticalLabelsHeightPercentage = DEFAULT_X_LABELS_HEIGHT_PERCENTAGE, } = config; const basePosition = height * verticalLabelsHeightPercentage; @@ -191,7 +192,9 @@ class AbstractChart< horizontalLabelRotation = 0, decimalPlaces = 2, formatYLabel = (yLabel: string) => yLabel, - verticalLabelsHeightPercentage = DEFAULT_X_LABELS_HEIGHT_PERCENTAGE + verticalLabelsHeightPercentage = DEFAULT_X_LABELS_HEIGHT_PERCENTAGE, + yAxisPosition = 'left', + width } = config; const { @@ -216,7 +219,10 @@ class AbstractChart< } const basePosition = height * verticalLabelsHeightPercentage; - const x = paddingRight - yLabelsOffset; + const x = + yAxisPosition === 'left' + ? paddingRight - yLabelsOffset + : width - (yLabelsOffset - 10); const y = count === 1 && this.props.fromZero ? paddingTop + 4 diff --git a/src/line-chart/LineChart.tsx b/src/line-chart/LineChart.tsx index 895e911a..4d890248 100644 --- a/src/line-chart/LineChart.tsx +++ b/src/line-chart/LineChart.tsx @@ -214,6 +214,10 @@ export interface LineChartProps extends AbstractChartProps { * The number of horizontal lines */ segments?: number; + /** + * The position of y axis + */ + yAxisPosition?: 'left' | 'right'; } type LineChartState = { @@ -815,7 +819,8 @@ class LineChart extends AbstractChart { formatXLabel = xLabel => xLabel, segments, transparent = false, - chartConfig + chartConfig, + yAxisPosition, } = this.props; const { scrollableDotHorizontalOffset } = this.state; @@ -893,7 +898,8 @@ class LineChart extends AbstractChart { paddingTop: paddingTop as number, paddingRight: paddingRight as number, formatYLabel, - decimalPlaces: chartConfig.decimalPlaces + decimalPlaces: chartConfig.decimalPlaces, + yAxisPosition: yAxisPosition, })}