indiespirit / react-native-chart-kit

📊React Native Chart Kit: Line Chart, Bezier Line Chart, Progress Ring, Bar chart, Pie chart, Contribution graph (heatmap)
https://expo.io/@indiespirit/react-native-chart-kit
MIT License
2.85k stars 658 forks source link

How to show 6 labels in Y-axis in Line-chart #716

Open harika-zazz opened 10 months ago

harika-zazz commented 10 months ago

Hi, i am using this library, it is working fine. I need to show 6 labels in y-axis. Right now it was showing 5 labels even if i declared 6 labels. I want to show 100 label in y-axis. How can i achieve this? I've changed the height also but it doesn't work. Please help me out this!

Code:-

function* yLabel() {
  yield* ["0", "20", "40", "60", "80", "100"];
}

  const yLabelIterator = yLabel();

 <LineChart
              bezier
              // withHorizontalLabels={false}
              // withVerticalLabels={false}
              yAxisInterval={2}
              data={{
                labels: ['Week 1', 'Week 2', 'Week 3', 'Week 4'],
                datasets: [
                  {
                    data: [10, 70, 60, 40, 20, 50],
                    strokeWidth: 2,
                    color: (opacity = 1) => `rgba(255,0,0,${opacity})`, // optional
                  },
                  {
                    data: [20, 40, 60, 80, 80, 90],
                    strokeWidth: 2,
                    color: (opacity = 1) => `rgba(0,0,102, ${opacity})`, // optional
                  }
                ],
                legend: ['Organic', 'Paid'],
              }}
              formatYLabel={() => yLabelIterator.next().value}
              width={Dimensions.get('window').width - 16}
              height={200}
              chartConfig={{
                backgroundColor: '#1cc910',
                backgroundGradientFrom: '#eff3ff',
                backgroundGradientTo: '#efefef',
                decimalPlaces: 2,
                color: (opacity = 1) => `rgba(0, 0, 0, ${opacity})`,
                style: {
                  borderRadius: 16,
                },
              }}
              style={{
                marginVertical: 8,
                borderRadius: 16,
              }}
            />

Screenshot 2023-12-04 at 4 24 26 PM

NoamKu95 commented 5 months ago

try adding the segments={5} property. The default is 4 + the 0 line = the 5 lines you are seeing now