Displaying the maximum value at the top of the graph in jqPlot's bar chart

I have a bar graph created using jqplot, featuring three values. I attempted to make the bar with the highest value reach the top of the chart, causing the heights of the other two bars to be recalculated accordingly. Below is the code I implemented:

        var value1 = 119, value2 = 91, value3 = 12;
        var s1 = [value1, value2, value3];
        var ticks = ['a', 'b', 'c'];

        plot7 = $.jqplot('chart7', [s1], {
            seriesColors:['#74b6e7', '#003246', '#e22a20'],
            gridPadding: {top:0, bottom:0, left:0, right:0},
            seriesDefaults:{
                renderer:$.jqplot.BarRenderer,
                shadow: false,
                rendererOptions: {
                    fillToZero: true,
                    barPadding: 0,
                    barMargin: 0,
                    barWidth: 51,
                    groups: 1,
                    varyBarColor: true
                },
                    //pointLabels: { show: false }
            },
            series:[
             {pointLabels:{
                show: true,
                labels:[ value1.toString(), value2.toString(), value3.toString()]
              }}],
            axes: {
                // yaxis: { autoscale: true },
                xaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer,
                    ticks: ticks
                },
                yaxis: {
                    min: 0,
                    max: value1
                }
            }
        });

The CSS styling applied:

        .jqplot-grid-canvas, .jqplot-xaxis, .jqplot-yaxis{ display: none;}
        .jqplot-point-label{ top: 129px!important; color: #fff;}
        #chart7{ width: 152px; height: 152px;}

Here's how the graph appears after applying the settings:

I am currently struggling to determine why the first point label is not displaying on the initial bar in the graph. Can anyone shed light on what might be incorrect in my setup?

Answer №1

Here is a solution to resolve the issue:

let num1 = 107, num2 = 84, num3 = 19;
let s2 = [num1, num2, num3];
let ticksArray = ['apple', 'banana', 'cherry'];

plot8 = $.jqplot('chart8', [s2], {
    seriesColors:['#45a9c1', '#823946', '#ff5722'],
    gridPadding: {top:10, bottom:0, left:5, right:3},
    seriesDefaults:{
        renderer:$.jqplot.LineRenderer,
        shadow: true,
        rendererOptions: {
            fillToZero: false,
            barPadding: 4,
            barMargin: 3,
            barWidth: 47,
            groups: 2,
            varyBarColor: false
        },
            //pointLabels: { show: true }
    },
    series:[
     {pointLabels:{
        show: false,
        labels:[ num1.toString(), num2.toString(), num3.toString()],
        location:'n',
        ypadding : 3,
        edgeTolerance : -2
      }}],
    axes: {
        // xaxis: { autoscale: false },
        xaxis: {
            renderer: $.jqplot.CategoryAxisRenderer,
            ticks: ticksArray
        },
        yaxis: {
            min: 10,
            max: num1
        }
    }
});

//adjusting the label display position
let heightValue = $(".jqplot-series-canvas").attr("height");
$(".jqplot-point-label").css("top",heightValue - 15);

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

I require displaying the initial three letters of the term "basketball" and then adding dots

Just starting out with CSS and struggling with the flex property. Seems to work fine at larger sizes, but when I reduce the screen size to 320px, I run into issues... Can anyone help me display only the first three letters of "basketball ...

Adding Material-UI icons dynamically in a React TypeScript project requires understanding the integration of imported icons

I have a collection of menu buttons with icons, stored in an array of objects. The icon names are saved as strings that correspond to Material UI icons: interface MenuButton { text: string, onClickFunction: Function icon: string } export defau ...

Flask application experiencing issues with loading CKEditor

Currently, I am working in PyCharm to develop a basic web application. My goal is to use CKEditor to allow for customization of certain form elements. To provide some context, here is the complete directory structure: <Root> -<app> -< ...

How to manage ajax URLs across multiple pages?

I have my website set up at http://example.com/foo/ within a directory, separate from the main domain. Through the use of .htaccess, I've configured the URLs to appear as http://example.com/foo/about/, http://example.com/foo/polls/, http://example.com ...

Angular: Verify that all services are fully executed before proceeding to the next step

We have adopted Angular for our project. Our component receives data from an API, which is then processed by Data Services. These services transform the data by combining first and last names, rounding dollar amounts, performing calculations, etc. The fina ...

Having trouble closing the phonegap application using the Back Button on an Android device

I've encountered an issue with my code for exiting the application. It works perfectly the first time, but if I navigate to other screens and then return to the screen where I want to close the app, it doesn't work. <script type="text/javascr ...

Looking for some help with tweaking this script - it's so close to working perfectly! The images are supposed to show up while

Hey everyone, I'm struggling with a script issue! I currently have a gallery of images where the opacity is set to 0 in my CSS. I want these images to become visible when scrolling down (on view). In this script, I have specified that they should app ...

to streamline the process of navigating Google Chrome web pages

Is it possible to create automation in Google Chrome that can complete the following tasks: 1. Input a job name to monitor 2. Periodically click a refresh button on the webpage (not the refresh button for the entire Chrome page in the left corner) 3. Open ...

How jQuery Mobile Navbar behaves with 4 elements instead of 5

I am currently experimenting with jQuery Mobile and I have come across a discrepancy. The documentation states that the navbar should wrap on five elements, but in my testing, it is wrapping at only four elements. Is this the expected behavior? Here is th ...

Selenium web driver showcases its capability by successfully launching the Firefox browser, yet encounters an issue with an invalid address

WebElement searchElement = driver.findElement(By.name("q")); searchElement.sendKeys("Selenium WebDriver"); searchElement.submit(); Displays "Search Results" public static void main(String[] args) { // TODO Auto-generated method st ...

Enhancing h1 styles in bootstrap with custom CSS styling

Currently, I am in the process of following a tutorial to familiarize myself with bootstrap. In the tutorial, they made changes so that it now looks like this: enter image description here Specifically, I am using the Montserrat font. However, when I atte ...

No longer able to bind events after making changes to SVG elements [using JSFiddle]

I've coded a personalized directive to display tags like `<rect>` and `<circle>` within `<svg>` elements. My shapes model is simply an array of objects with different attributes such as `width`, `height`, and `stroke-width. These s ...

issue arising from unique style identifiers in FireFox while making changes to styles via document.styleSheets

While experimenting with altering some stylesheets using JavaScript, I encountered an interesting issue: When attempting to set an attribute on a style rule in Firefox and the property is one of their proprietary ones, it fails silently. To demonstrate th ...

Tips for extracting only the filename from chokidar instead of the entire file path

I am trying to capture the filename that has been changed, removed, or renamed, but I am currently receiving the full file path. Question: How can I extract only the filename when it is changed, instead of working with the entire file path? This is what ...

An easy way to ensure IE opens PDF links in an iframe in a new tab

I've encountered an issue while trying to display pdf files on an html page using an iframe. Here's my code snippet: <iframe src="testfile.pdf" width="100%" height="100%"></iframe> My problem is that the links within the pdf always ...

A guide on utilizing mockDOMSource for testing a sequence of actions within Cycle.js

Although I am aware that there might be a more efficient way using cycle/time, my main focus is to grasp the fundamentals. For some reason, my action$ stream does not appear to be functioning; I have attempted to create multiple mock doms using xs.period ...

Creating a border around an SVG element using the background color of its parent container

I am aiming to layer 2 SVGs on top of each other. The top SVG will have an outline to make it stand out more from the bottom SVG. These SVGs are embedded on buttons with transitions and hover colors. I want the outline SVG to match the background color of ...

What could be causing the Angular HTTPClient to make duplicate REST calls in this scenario?

I am encountering an issue with my Angular service that consumes a Rest API. Upon inspecting the network and the backend, I noticed that the API is being called twice every time: Here is a snippet of my Service code: getAllUsers():Observable<any>{ ...

Transform the look of your bootstrap 5 inputs by making them dark-themed

I have a feature in my app that allows users to switch between light and dark modes. Currently, I am using Bootstrap 5 form-control inputs and want to customize their background color based on the mode selected. Which CSS classes do I need to target in or ...

What methods can I implement to showcase random images in JavaScript using a JSON array value?

I am currently working on a fun avatar generator project. The challenge I'm facing is that each hairstyle consists of two parts (front and back), and when loaded randomly, the colors don't always match. To tackle this issue, I have organized the ...