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.84k stars 658 forks source link

Can i use multiple lines in Line graph? #23

Closed mrfambo closed 6 years ago

mrfambo commented 6 years ago

Is it possible to have multiple lines in line graph, i mean if i provide data for each line

mrfambo commented 6 years ago

Is there anyone to reply on this Issue ?

Hermanya commented 6 years ago

Yeah, Hi! The datasets API would seem like it allows for that, but the functionality is not implemented. There is a problem, that these charts are monochrome (everything is the same color), and it would be difficult to differentiate the multiple lines.

mrfambo commented 6 years ago

I tried editing datasets api too, provided it with array of more datasets but i couldn't see anything happening in it. Any solution, i need it badly though !!!

Hermanya commented 6 years ago

I think the only solution is to implement this functionality in the line chart, but unfortunately I don't have time to do it today.

mrfambo commented 6 years ago

If you check the render, it is taking datasets[0], that means it is taking the first index and ignoring others, i forked repository but couldn't run it. It is saying react-native is not in dependancies. If i know the basics of running it, i can manage to change the rendering of line graph and include mapping to go through all the datasets indexes. If you can help me up and running with this repo i will be very thankful to you. I did following:

  1. Forked it
  2. Cloned It
  3. Ran "yarn"
  4. "yarn run ios" also "react-native run-ios"

but i couldn't manage to run it.

mrfambo commented 6 years ago

@Hermanya

Hermanya commented 6 years ago

Checkout https://github.com/indiespirit/react-native-chart-kit/blob/master/contributing.md

You need to change "main" in package json.

The react-native not being a dependency is somewhat expected. It's a peerDependency. It's required for running, but for the purpose of it being a library, o cannot set it on regular dependencies.

mrfambo commented 6 years ago

@Hermanya

I managed to change the code and can render the multiple lines on Charts except for Bazier lines. There is a small issue with a callback of getBezierLinePoints.

Hermanya commented 6 years ago

If you create a PR, I will take a look later.

mrfambo commented 6 years ago

Bazier line points are returning as,

M64,NaN Q 78.25, NaN, 92.5, NaN Q 106.75, NaN, 121, NaN Q 135.5, NaN, 150, NaN Q 164.5, NaN, 179, NaN Q 193.5, NaN, 208, NaN Q 222.5, NaN, 237, NaN Q 251.5, NaN, 266, NaN Q 280.5, NaN, 295, NaN Q 309.5, NaN, 324, NaN Q 338.5, NaN, 353, NaN

mrfambo commented 6 years ago

Sure @Hermanya

mrfambo commented 6 years ago

Uuuhh Uuuhhh,

I have managed to done it :P Tested On multiple datasets. Its working like a charm. Would you like to check it? I would love to have it on board :D

It will be my first Open Source Contribution :D

Hermanya commented 6 years ago

Nice, congrats. Please open a PR!

mrfambo commented 6 years ago

@Hermanya Done

Hermanya commented 6 years ago

Thanks I'll take a look after the game (Russia Croatia)

mrfambo commented 6 years ago

@Hermanya What a sizzling match it was !!! Feeling sad for Russia.

RikTheunis commented 6 years ago

Hi @alimuqaddas, what is the recommended way to show the 2 lines?

rzdev commented 5 years ago

@mrfambo i'm having issue with the following datasets

const data = { labels: ['January', 'February', 'March', 'April', 'May', 'June'], datasets: [{ data: [ 50, 50, 50, 50, 50, 50 ] },{ data: [ 20, 20, 20, 20, 20, 20 ] },{ data: [ 67, 67, 67, 67, 67, 67 ] }] };

it should show 3 lines, but only 1 line is shown

mrfambo commented 5 years ago

@rzdev which version are you using?

rzdev commented 5 years ago

@mrfambo thank you for your quick reply, i'm using react-native-chart-kit v1.2.1

rzdev commented 5 years ago

it seems other user have found similar issue https://github.com/indiespirit/react-native-chart-kit/issues/70

prasad456 commented 5 years ago

I'm using 2.0.1 version I have two graphs to display one graph should display two lines and other should display four lines, but only two lines graph is showing for the second graph only one line is displaying if converted the second graph its showing as single line only?

Ahmad5448 commented 4 years ago

sir Ali how did you do that ??? now I need it badly

iamadityaaz commented 4 years ago

This is the code which helped me to achieve the following Output : Code :

                             <LineChart
                    bezier
                    withHorizontalLabels={false}
                    withVerticalLabels={false}
                    data={{
                        labels: [' 1', ' 2', ' 3', ' 4', ' 5', ' 6'],
                        datasets: [
                            {
                                data: [1, 7, 6, 4, 2, 5],
                                strokeWidth: 2,
                                color: (opacity = 1) => `rgba(255,0,0,${opacity})`, // optional
                            },
                            {
                                data: [2, 4, 6, 8, 8, 2],
                                strokeWidth: 2,
                                color: (opacity = 1) => `rgba(0,0,102, ${opacity})`, // optional
                            },
                            {
                                data: [9, 4, 7, 8, 2, 4],
                                strokeWidth: 2,
                                color: (opacity = 1) => `rgba(0,102,0, ${opacity})`, // optional
                            },
                        ],
                        legend: ['Maths', 'SOM', 'DS'],
                    }}
                    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,
                    }}
                />

Output

image

EskimoEmoji commented 3 years ago

Is there a way to have the Y and X-axis labels to show? Edit: lol I justed needed to remove withHorizontalLabels={false} withVerticalLabels={false}

Thanks for the above code! very useful

EskimoEmoji commented 3 years ago

Would there be a way to set specific X & Y coordinates values? I'm running into the issue with multiple lines of different length data, that the points are not on the correct X value, only the correct Y value. Thanks

Topstar0520 commented 3 years ago

Good

quicksilverr commented 3 years ago

@Hermanya @mrfambo Is there a way, to change the shadow colors for each of the graphs?

I see, a renderShadow function, in the LineGraph component, can we extract the data.datasets color, option and then use it there?

quicksilverr commented 3 years ago

@Hermanya @mrfambo Here's the link to a similar StackOverFlow Question -> https://stackoverflow.com/questions/65965084/react-native-chart-kit-different-shadow-color

It would be a great feature, that we can add to it.

reimibeta commented 2 years ago

datasets: statistics.map((d: any) => { return { data: d.data, color: (opacity = 1) => d.borderColor} })

replace on datasets

hamzakashifCL commented 1 year ago

This is the code which helped me to achieve the following Output : Code :

                             <LineChart
                  bezier
                  withHorizontalLabels={false}
                  withVerticalLabels={false}
                  data={{
                      labels: [' 1', ' 2', ' 3', ' 4', ' 5', ' 6'],
                      datasets: [
                          {
                              data: [1, 7, 6, 4, 2, 5],
                              strokeWidth: 2,
                              color: (opacity = 1) => `rgba(255,0,0,${opacity})`, // optional
                          },
                          {
                              data: [2, 4, 6, 8, 8, 2],
                              strokeWidth: 2,
                              color: (opacity = 1) => `rgba(0,0,102, ${opacity})`, // optional
                          },
                          {
                              data: [9, 4, 7, 8, 2, 4],
                              strokeWidth: 2,
                              color: (opacity = 1) => `rgba(0,102,0, ${opacity})`, // optional
                          },
                      ],
                      legend: ['Maths', 'SOM', 'DS'],
                  }}
                  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,
                  }}
              />

Output

image

is there a way to hide points in multiple line chart, the function hidePointAtIndex just take single number array[]. So, how can we do it for multiple lines chart