Tips for aligning multiple apex pie charts side by side

I am currently utilizing ReactApexChart to display pie charts in a React application. I am trying to have four pie charts aligned horizontally within a single div, but by default, the charts are displayed vertically with each chart in its own separate div. Unfortunately, the documentation has not been helpful in resolving this issue.

render() {
        const { isLoading } = this.state;

        const options = {
            labels: ['Dynatrace', 'Splunk', 'Status cake', 'Datadog'],
            responsive: [{
              breakpoint: 480,
              options: {
                chart: {
                  width: 200
                },
                legend: {
                  position: 'bottom'
                }
              },
            }]
          };

        const series = [44, 55, 13, 43];

        return(
            <Fragment>
                {
                    isLoading && <Loader />
                }
                <div>
                 <ReactApexChart options={options} series={series} type="pie" width="380" />
                 <ReactApexChart options={options} series={series} type="pie" width="380" />
                 <ReactApexChart options={options} series={series} type="pie" width="380" />
                 <ReactApexChart options={options} series={series} type="pie" width="380" />
                </div>
            </Fragment>
        )
    }
}

Answer №1

  1. To start, import the necessary CSS file (e.g., MyCharts.css)
  2. Within the div tag you've created, include a className attribute (e.g., charts):
import "./MyCharts.css";

// The remainder of the code remains unchanged, but make sure to include it

<div className="charts">
    <ReactApexChart options={options} series={series} type="pie" width="380" />
    <ReactApexChart options={options} series={series} type="pie" width="380" />
    <ReactApexChart options={options} series={series} type="pie" width="380" />
    <ReactApexChart options={options} series={series} type="pie" width="380" />
</div>

// The rest of the code I didn't change, but of course you need to add it as well
  1. In your CSS file (e.g., MyCharts.css), define the required styles like so:
.charts div {
    display: inline-block;

    /*
        Optionally, if you want to horizontally align text with the charts,
        ensuring they appear in the center of the text line
    */
    vertical-align: middle;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way for me to retrieve the current value of a star rating when I click on it?

Looking for assistance with a ReactJS rating stars component that behaves oddly. The starting value is set to 5 stars, but each click on the stars seems to return the previous value rather than the current one. import React, {useState} from "react&quo ...

Storing and updating data efficiently in React Native applications

I'm facing a dilemma with a dynamic database in my React Native app. The values in the database are constantly changing, and I need to figure out the best way to store and update this data within the application. Specifically, I have a single table w ...

Exploring the potential of Framework7 in Single Page Applications: optimizing performance by preloading

I'm currently working on developing a web application using Framework7. Framework7 offers routing APIs for navigating between HTML pages. It seems that the pages are loaded dynamically through AJAX requests. I am curious if it is possible to preload ...

Ways to adjust the size of an HTML fieldset?

Is there a way to decrease the space between the paragraph and the border of this fieldset? I attempted to adjust the margins in the following manner: fieldset { margin: 1px; margin-top: 2px; border-top-right-radius: 1px; } <fieldset> < ...

The key to highlighting the search terms in bold format

How can I highlight the search terms entered by users in the search box? I want all keywords in every search result to be bolded. For example, when a search term is entered and the results page displays all results with the typed term in bold within each ...

Tips for Embedding React into a Specific ID using Hooks on an HTML Document

I am currently diving into the world of React hooks. While I understand class components, Hooks seem to be missing a specific render section. When adding React to a webpage (without using CREATE REACT APP), how do I specify where my hook should run on the ...

Creating a unique 'full height' feature for the Material UI Dialog modal component

I'm encountering an issue with the fullScreen property on the Material UI Dialog component, which is being used as a modal. Following the documentation's recommendation, my code looks like this: import useMediaQuery from '@material-ui/core/u ...

How can the spacing between Angular Material's mat-card-content and mat-card-actions be adjusted?

I am creating a mat card layout where there are two separate cards within the main card's content section. However, when I add a button for the actions section of the main card, there is no spacing between these two sections. How can I create a vertic ...

Utilizing jQuery in non-React JavaScript with Rails- A Guide

I've recently integrated The react_on_rails (NOT react-rails) Gem into my Rails 4.2 project. I am looking to add new React components to an application that already contains a substantial amount of JavaScript code. After running the "hello world" ge ...

Learn how to center content and stretch a column using Vuetify frameworks

Looking for a layout with 2 columns of equal height and centered content vertically? Here's how to achieve it using Vuetify! Check out the code snippet below: <div id="app"> <v-app> <v-row align="center"> ...

Trouble displaying portrait images in CSS slideshow

My portfolio includes an image slider called wow slider, which can be found at You can view my site with the image slider on this page: http://jackmurdock.site50.net/StudioWork.hmtl While most of the galleries display portrait and landscape images correc ...

Encountering the error message "SyntaxError: Cannot use import statement outside a module" is often linked with the mui-color-input component and Create React App

After integrating the mui-color-input library into my create-react-app project, I encountered a problem with the component test despite the project building successfully. ● Test suite failed to run Jest encountered an unexpected token Jest fai ...

Apollo-client effortlessly loads and merges data from the server with ease

After reviewing the example code at: https://www.apollographql.com/docs/tutorial/mutations/ If the login form mutation were to return both a JWT token and the user's profile, is there a method to store this profile data in the client cache so that we ...

The unitPngFix plugin ensures that the display of hidden div elements cannot be altered

I have been trying to resolve an issue with PNG files and transparency in IE browsers on my website. I have made progress, but there seems to be a problem specifically with IE6. To display transparent PNG images correctly on my site in IE browsers, I am u ...

What is the best way to address a row of hyperlink text located at the top of a webpage?

I have encountered an issue where three rows of text links near the top of a page shift up to the very top when a link is pressed, causing them to obscure a line of text that was already at the top. How can I keep the position of these three rows anchored? ...

Retrieve Data with Conditions using the Json Placeholder API

I have been working on integrating my posts with the user table using the Json PlaceHolder API and nextJS for the past couple of days. Despite trying different approaches, I haven't been able to figure out the right logic yet. Any guidance or assistan ...

The issue of links not updating the DOM in ReactJS when clicked

I am encountering an issue where the data loads properly for the first time, but when I click on the filter buttons like latest or top, the AJAX request is being sent successfully but the view is not updating. As a newcomer to React JS, I am not sure what& ...

React app is having issues with Hammer.js when used together with touch emulator on touch devices

I've been experimenting with testing touch events using Hammerjs in React, and I'm facing quite inconsistent behavior across different browsers and events. Consider this basic code snippet: import React from 'react'; import PropTypes ...

Failed react-query mutation results in "Uncaught (in promise)" error

Recently updated my react-scripts from version 4 to 5, but now encountering an issue with react-query ^3.34.8. The problem arises when I reject a promise in the useMutation, triggering the runtime error Uncaught (in promise): // Component.js import useDel ...

What is the best way to increase the size of an image within a card and minimize the amount of white space

I have a card featuring an image, accompanied by a banner placed next to it. To structure this layout, I am using col-lg-8 for the card and col-lg-4 for the banner. However, I'm facing an issue with excessive white space between the card (which has a ...