What steps can I take to ensure the legend does not get cropped in angular-google-chart?

I have been trying to implement a Google bar chart using angular-google-chart by referring to the example provided here. However, I am facing an issue where my labels and legends are only partially visible in the image below. How can I display the full text properly?

https://i.sstatic.net/eL3N7.png

Below is the code snippet I have used:

angular.module("google-chart-sample", ["googlechart", "googlechart-docs"])
.controller("GenericChartCtrl", function ($scope) {
    $scope.chartObject = {};

    $scope.chartObject.type = "BarChart";

    $scope.onions = [
        {v: "Onions"},
        {v: 3},
    ];

    $scope.chartObject.data = {"cols": [
        {id: "t", label: "Topping", type: "string"},
        {id: "s", label: "Slices", type: "number"}
    ], "rows": [
        {c: [
            {v: "Mushrooms"},
            {v: 3},
        ]},
        {c: $scope.onions},
        {c: [
            {v: "Olives"},
            {v: 31}
        ]},
        {c: [
            {v: "Zucchini"},
            {v: 1},
        ]},
        {c: [
            {v: "Pepperoni"},
            {v: 2},
        ]}
    ]};

    $scope.chartObject.options = {
        'title': 'How Much Pizza I Ate Last Night'
    };
});

Answer №1

To avoid legend labels from getting cut off, you can utilize the chartArea property:

An object with settings to adjust the position and dimensions of the chart area (the area where the chart itself is displayed, excluding axes and legends). Two formats are supported: a number or a number followed by %. A single number represents a value in pixels; a number followed by % indicates a percentage.

For example:
  chartArea:{left:20,top:0,width:'50%',height:'75%'}

Type: object Default: null

Illustration

angular.module("google-chart-sample", ["googlechart"])
.controller("GenericChartCtrl", function ($scope) {
    $scope.chartObject = {};

    $scope.chartObject.type = "BarChart";


    $scope.chartObject.data = {
        "cols": [
            { id: "t", label: "Topping", type: "string" },
            { id: "s", label: "Slices", type: "number" }
        ], "rows": [
            {
                c: [
                   { v: "Mushrooms" },
                   { v: 3 },
                ]
            },
            { c:  [
                   { v: "Onions" },
                   { v: 3 },
                  ] 
            },
            {
                c: [
                   { v: "Olives" },
                   { v: 31 }
                ]
            },
            {
                c: [
                   { v: "Zucchini" },
                   { v: 1 },
                ]
            },
            {
                c: [
                   { v: "Pepperoni" },
                   { v: 2 },
                ]
            }
        ]
    };

    $scope.chartObject.options = {
        'title': 'How Much Pizza I Ate Last Night',
        chartArea: {  width: "60%" }
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.18/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-google-chart/0.0.11/ng-google-chart.js"></script>
<div ng-app="google-chart-sample" ng-controller="GenericChartCtrl">
    <div google-chart chart="chartObject" style="height:600px; width:480px;"></div>
</div>

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

Animate jQuery Images - Transform and smoothly reveal element

Hey there! I've managed to create a color switcher that gives a sneak peek of different themes. Currently, it simply switches the image source and loads the new image. But I'm curious if it's possible to add a fadeIn effect to enhance the t ...

Scrolling in iOS 8 causing flickering problem with background image

Utilizing the Supersized jQuery slider plugin to create a full-page background slider with a fade-in effect and added height for scrolling. The slider functions correctly on desktop, but upon testing on an iOS 8 iPad device, there is noticeable flickering ...

What is the best way to connect two web workers in HTML5?

I've been delving into the web workers documentation, but I'm coming up short on finding an API that facilitates direct communication between two web workers. The scenario I have is needing to establish a direct line of communication from worker1 ...

Strategies for reliably causing IE 10&11 to crash? Simulating the phenomenon of "Internet Explorer abruptly closing and reopening the tab"

Here's an interesting query. Is there a method to consistently trigger this error in Internet Explorer 10 & 11 using Javascript, CSS or HTML? An issue with this website is forcing Internet Explorer to close and reopen the tab. I'm not trying ...

Possible scope problem causing AngularJS image preview not showing up in ng-repeat loop

I came across this question and made some modifications. It works well when used outside of the ng-repeat. However, I'm facing issues when trying to use it within my repeat loop; the image.src does not update. I believe this is more related to the sc ...

The most effective method for transferring a JavaScript object between a TypeScript frontend and a Node.js backend

I need some advice on how to effectively share a JavaScript object between my Angular2 with Typescript frontend and NodeJS backend in an application I'm working on. Currently, I am using a .d.ts file for the frontend and adding a module.exports in the ...

Change the value of the material slide toggle according to the user's response to the JavaScript 'confirm' dialogue

I am currently working on implementing an Angular Material Slide Toggle feature. I want to display a confirmation message if the user tries to switch the toggle from true to false, ensuring they really intend to do this. If the user chooses to cancel, I&ap ...

Importing files in electron without using babel

I am in the process of converting a web application into an electron app. I have organized my functions in various files and imported them into my main.js using a transpiler. However, as I try to execute this in my electron app, I encounter an issue with ...

Can you focus on the central area of the visible picture?

My current project involves developing an e-comic book reader in electron, and I am facing a math-heavy challenge. I want to implement a zoom functionality that doesn't just enlarge from the top-left corner but instead zooms in from the center. @100% ...

Guide for creating a smooth fade in/out effect for the "Show More" feature in Vue

This is my current Lorem Ipsum page. When I click the Lorem button, the text will be expand or collapse. https://i.sstatic.net/BldW4.png I attempted to modify the css below to create a fading effect for the hidden text. @keyframes open { from { li ...

Difficulties arise when attempting to display an input within a Bootstrap modal

Upon clicking an icon, I aim to display a bootstrap modal prompting the user to input text and a date. I have adapted code from W3Schools to create the necessary form. Unfortunately, when the button is clicked, only the labels and text area are shown, not ...

Encountered an issue resolving the module specifier "stimulus-autocomplete"

Ruby 3.0.3 Rails 7.0.0.alpha2 Upon completing the steps for installation and usage, I started the server only to encounter the following error message: Uncaught TypeError: Failed to resolve module specifier "stimulus-autocomplete". Relative refe ...

Updating state in Redux from a different componentorModifying state

I'm currently learning about redux and I'm facing an issue with accessing the stored state (id) in my components. Specifically, I have a Footer component with a button that is supposed to modify the state in the Layout component. However, I am un ...

Importing named exports dynamically in Next.js

Currently, I am in the process of learning Next.js and I want to utilize a function called getItem from the package found at https://www.npmjs.com/package/encrypt-storage In my attempt to do so using the code snippet below, I encountered an error stating ...

Managing a two-dimensional array in AngularJS: tips and tricks

I have a JSON source that provides me with a double array: // Function and module code omitted .. $scope.texts = [ ['Small sheep and ham.'], ['Ducks go moo.', 'Helicopters and racecars go bang!'] ]; My goal is to display ...

How can I add both the keys and values to an array in order to construct a dynamic query?

When building the query object for MongoDB, I encountered an issue with the output. Here is what I got: output {"$match":{"$and":[{id:1},{name:"Alfred"},{location:"moon"},{"values":{"$in":[{name: ...

Defining a Global Variable using the jQuery $(this)

I have been looking for ways to simplify my coding process, and one method I've tried is assigning a global variable. var parent = $(this).parent().parent().parent(); var parentModule = $(this).parent().parent().parent().parent(); Throughout my code ...

The variable being attempted to read is undefined, resulting in an error

I am attempting to access the title property of the first item in an array of objects. Interestingly, when I manually enter the following code in Chrome's JavaScript developer console: hello.example.array[0].title I successfully retrieve the title. ...

Issues with importing Bootstrap in JavaScript

Utilizing Bootstrap in both HTML and JavaScript/TypeScript has been my recent endeavor. I have successfully imported the minified versions of Bootstrap JS and CSS in my HTML file and incorporated this line of code in my TypeScript: import * as bootstrap fr ...

Combining routes in Express and Angular can be achieved by leveraging the power

How can I successfully integrate Jade AngularJS with ExpressJS? I have an app.js file for Express to run the server using Grunt. This app.js file renders home.jade which leads me to the home page. On the homepage, I have implemented AngularJS. I also creat ...