0

I want to edit the style of my chart as follows:

Spected Result

But I have come to this point:

Current Graph

Where the only thing I would be missing is to make the line a little sharper and not look like it has opacity and remove the fill from the graph so that only the line remains.

This is my code:

import React from 'react';
import { ScrollView, Dimensions, View, Text } from 'react-native';
import {
     LineChart,
     BarChart,
     PieChart,
     ProgressChart,
     ContributionGraph,
     StackedBarChart
   } from "react-native-chart-kit";

 import Styles from './Styles';

 export default function Charts(){
 const chartConfig = {
    backgroundGradientFromOpacity: 0,
    backgroundGradientToOpacity: 0,
    color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
    strokeWidth: 3, 
    barPercentage: 0.5,
    useShadowColorFromDataset: false,
    propsForBackgroundLines: {
        strokeDasharray: "",
        strokeOpacity: 0.0
    },

  };


return (
    <View>
        <ScrollView>
            <View style={[Styles.chart.card]}>
                <LineChart data={{
                                labels: ["January", "February", "March", "April", "May", "June"],
                                datasets: [
                                            {
                                                data: [
                                                    Math.random() * 100,
                                                    Math.random() * 100,
                                                    Math.random() * 100,
                                                    Math.random() * 100,
                                                    Math.random() * 100,
                                                    Math.random() * 100
                                                ]
                                            }
                                        ]
                                }}
                                width={Dimensions.get("window").width}
                                height={300}
                                yAxisLabel={undefined}
                                yAxisInterval={undefined}
                                chartConfig={chartConfig}
                                withHorizontalLabels={false}
                                bezier
                                hidePointsAtIndex={[0, 1, 2, 3, 4, 5]}
                                style={{
                                }}/>
            </View>
        </ScrollView> 
    </View>
    
  );
}

I'm using React Native with Expo and the React-Native-Chart-Kit library.

Also if there is any other library that allows a greater customization of charts much better.

Thanks for your help.


1 Answer 1

0

I found the solution, I adjusted the chartConfig like this:

const chartConfig = {
    backgroundGradientFromOpacity: 0,
    backgroundGradientToOpacity: 0,
    color: () => `rgba(255, 255, 255, 1)`, /* Avoid opacity */
    strokeWidth: 3, 
    barPercentage: 0.5,
    useShadowColorFromDataset: false,
    propsForBackgroundLines: {
        strokeDasharray: "",
        strokeOpacity: 0.0
    },

    /* Adjusts the fill of the chart */
    fillShadowGradient: 'transparent',
    fillShadowGradientOpacity: 0,
    fillShadowGradientFromOffset: 0,
    fillShadowGradientTo: 'transparent',
    fillShadowGradientToOpacity: 0,

  };

Result:

Final Result

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.