Expanding canvas due to the utilization of column-count

I am currently working with chart.js and have a setup that includes two pie charts and a bar chart that I would like to display in a single row. In order to achieve this layout where the bar chart is larger than the pie charts, I implemented the following solution.

To ensure that the two pie charts fit into a single column, I utilized the column-count property in CSS.

Below is the CSS code that I have implemented:

.container {
    display: flex;
}

.row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    margin-bottom: 30px;
}

.column {
    display: flex;
    flex-direction: column;
    flex-basis: 100%;
    flex: 1;
    align-self: stretch;
    margin-right: 10px;
    margin-left: 10px;
}

.container div {
    flex: 1;
}

canvas {
    max-width: 100%;
    display: flex;
}


.pie {
    column-count: 2;
    max-height: 93%;
}

Additionally, here is the corresponding HTML structure:

<div class="container">
    <div class="row">
        <div class="pie">
            <canvas baseChart [data]="pieFeeChartData" [type]="pieChartType"
                [options]="pieFeeChartOptions">
            </canvas>
            <canvas baseChart [data]="pieFooChartData" [type]="pieChartType"
                [options]="pieFooChartOptions">
            </canvas>
        </div>
        <div class="column">
            <canvas baseChart [data]="barBlahChartData"
                [options]="barBlahChartOptions" [type]="barChartType">
            </canvas>
        </div>
    </div>
</div>

Although setting max-height: 93% in the .pie class seems to provide a close approximation of the desired layout, it lacks precision and may result in inconsistent formatting on smaller window sizes. An ideal solution would be to avoid using hardcoded values. I have experimented with various flex settings, but I aim to maintain consistency in CSS styling across the project.

You can view a screenshot of the current layout without the max-height: 93% setting here.

Answer №1

Utilizing grid layout can significantly streamline your design process, providing more consistent outcomes and enhancing reusability as your project expands. It also simplifies the process of understanding and managing your project as it grows.

Additionally, take note of how the height value for the canvas element utilizes !important to override the fixed height values applied inline by Chart.js.

.container {
  width: 90%;
  margin: auto;
}

.row {
  display: grid;
  /* 
    A standard 12 column grid can be evenly 
    divided into quarters and thirds.
  */
  grid-template-columns: repeat(12, 1fr);
}

.col-full {
  grid-column: span 12;
}

.col-half {
  grid-column: span 6;
}

.col-quarter {
  grid-column: span 3;
}

/* ✨ Magic ✨ */
canvas {
  max-width: 100%;
  height: 100% !important;
}

Here is the corresponding HTML structure:

<div class="container">
  <div class="row">
    <div class="col-quarter">
      <canvas id="pieChart1"></canvas>
    </div>
    <div class="col-quarter">
      <canvas id="pieChart2"></canvas>
    </div>
    <div class="col-half">
      <canvas id="barChart"></canvas>
    </div>
  </div>
</div>

Observe the outcome: https://i.sstatic.net/UCJSh.png

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

leveraging the default browser behavior for the href and target attributes within an <a> element in Angular 2

How can the behavior of a simple anchor tag in Angular 2 be implemented without being overridden by the routing module? <a href="some url" target="_whatever"> It is crucial to prevent the routing module from highjacking the URL using the base href. ...

While attempting to scrape data, the console.log function displays the information, however it is not being returned

This code is now working perfectly! However, I am struggling to organize the data into an array of separate objects. getGAS: function(url) { var self=this; rp(options) .then(($) => { let gasset = []; $('.stations-list').each(functio ...

Having trouble importing PouchDB into an Angular 5.2.0 project

Struggling with integrating PouchDB into my Angular project, I've experimented with various import methods : import PouchDB from 'pouchdb'; import * as PouchDB from 'pouchdb'; In my service, I'm utilizing it like this : dat ...

Submitting Angular Reactive Forms with Validation Reset

I am currently working on a reactive form <form [formGroup]="secondFormGroup"> <ng-template matStepLabel>enter items</ng-template> <div style="display: flex; flex-direction: column;"> <mat-form-field> ...

Grow your website horizontally rather than vertically for a unique user experience

When I align divs to the right, they start stacking up and crowding on top of each other. When there are more than 4 divs, the fifth one jumps below the rest as the page expands downward. I want to prevent this from happening. Instead, I would like the h ...

JavaScript PIP video feature

Currently, I am utilizing the requestPictureInPicture function to display the HTML video element in a popup window. However, I have encountered an issue where the size is restricted to approximately 920 x 540 when in Picture-in-Picture mode. I am wonderin ...

My media queries refuse to cooperate until I add the magical "!important" declaration

Utilizing Bootstrap 4 along with a custom CSS file on my website. Within the CSS file, I have included some media queries at the bottom: @media (max-width: 575px) { .address .contact { text-align: center; } } /* Small devices (tablets, 768px and ...

Ways to determine the number of duplicate items in an Array

I have an array of objects that contain part numbers, brand names, and supplier names. I need to find a concise and efficient way to determine the count of duplicate objects in the array. [ { partNum: 'ACDC1007', brandName: 'Electric&apo ...

Tips for displaying multiple pages of a Power BI embed report on Mobile layout within the host application

I created a Power BI embed application using Angular on the frontend and C# on the backend. The issue I am facing is that when viewing Power BI reports in mobile layout, reports with multiple pages only show the default page and do not display the other pa ...

What could be causing the no-repeat functionality to fail on these background images, and what steps can be taken to prevent the list text from overlapping with the image?

UPDATE EDIT. There is still an unresolved issue with this problem. Although setting the background to no-repeat fixed the image repetition problem, the list item text still overlaps the background image and there is an extra tick to the left. Please refer ...

The ngx-translate/core is throwing an error message that says: "HttpClient provider not found!"

I recently downloaded the ngx-translate/core package and have been diligently following the provided documentation. However, I'm facing an issue with getting the translations to work. Here are the steps I've taken: 1] Definition in the AppModul ...

Tips for setting up the image as the header background in HTML5 and CSS3

I am currently designing a website. I'm wondering if there is a way to create a div with a curved bottom using HTML5, CSS3 and JavaScript. It should resemble the design of the curved header bottom ...

Connecting the output of an *ngFor loop to a universal variable

*ngFor="let item of items | filter:{ name: searchString } : searchString as filteredItems" and then afterwards <button (click)="doSomething(filteredItems)> The variable filteredItems is a local variable that is only accessible within the *ngFor lo ...

Is there a way to enlarge images when hovered using canvas?

I came across a fascinating example at the following link: , where the images expand when hovered over. I am aware that this can be achieved using jquery, but I have concerns about its speed and reliability. I would like to experiment with d3.js, although ...

Notify when the button value changes to "submit"

I recently added a jQuery form wizard to my website. I want users to receive an alert in JavaScript when they reach the end of the form. To achieve this, I inserted a simple JavaScript code at the beginning of my page within <head>..some code</hea ...

Learn the best practices for sharing .env values from the main project component to various reusable npm installed components

In recent projects I've worked on using React and Vue.js, I have utilized .env variables to store API URLs for micro services and other configuration settings that are used throughout the root project. However, when it comes to child components insta ...

Execute MySQL query when the content of an HTML text field changes

My goal is to check if the value entered in an input text box matches any rows in a database. I want the DB to be searched when text is typed into the input field. <input type='text' name='barcode'> I would like it to search the ...

How to assign a global variable in Angular 2 from within a promise

I have encountered a strange issue while trying to assign a response to a global variable inside an observable. Here's the logic of my program: Fetch the latest playlists IDs from elastic search (using a type definition file for elastic search). T ...

Update the value of the following element

In the table, each row has three text fields. <tr> <td><input type="text" data-type="number" name="qty[]" /></td> <td><input type="text" data-type="number" name="ucost[]" /></td> <td><input ty ...

Looking to implement browserDetection functionality in your Angular 4 application?

I am currently in the process of transitioning from Angular2 to Angular4. However, I encountered an error in Angular4: component: import { browserDetection } from '@angular/platform-browser/testing/src/browser_util'; if (browserDetection.isWe ...