react-native-chart-kit icon indicating copy to clipboard operation
react-native-chart-kit copied to clipboard

How to send values in the x-axis and y-axis in data?

Open Ranjit8298 opened this issue 2 years ago • 4 comments

Hi all, How to send values in the x-axis and y-axis in data? like this { data: [ {x: '200', y: 30}, {x: '210', y: 40}, {x: '220', y: 50}, {x: '230', y: 60}, {x: '240', y: 70} ], color: (opacity = 1) => rgba(255, 0, 0, ${opacity}), // optional strokeWidth: 2, // optional },

Ranjit8298 avatar Mar 31 '23 10:03 Ranjit8298

Hi @Ranjit8298, if you follow the docs example, you have set the data prop for the x-axis and y-axis data as shown in the below example

data={{
           labels: [], /*x-axis values array*/
           datasets: [
                   {
                     data:[] ,/*y-axis values array*/
                     strokeWidth: 2, // optional
                   },
           ],
}}

bilal1031 avatar Apr 01 '23 17:04 bilal1031

Hi @Ranjit8298

This is how you would send in the values into the x-axis and y-axis.

const chartData = { labels: ['200', '210', '220', '230', '240'], /x-axis values array/ datasets: [ { data: [30, 40, 50, 60, 70], /y-axis values array/ strokeWidth: 2, // optional }, ], };

OR

const chartData = { labels: data.map((item) => item.x), datasets: [ { data: data.map((item) => item.y), strokeWidth: 2, }, ], };

namzo198 avatar Apr 02 '23 07:04 namzo198

Thanks @namzo198 and @bilal1031 You are right. I can use it like this but how can I use it in multi-line charts or when we have multiple x-axis?

Ranjit8298 avatar Apr 04 '23 06:04 Ranjit8298