Highcharts is not displaying the background image

As a vital part of this large-scale web-service based application, my role is to integrate graph legends onto the dynamically generated graphs. Upon joining the project, I encountered an error message when attempting to load images using incorrect paths.

Despite efforts such as adjusting Z-indexes and positions within the CSS, only text displays while images remain absent due to restrictions in tag usage.

Below is the relevant CSS snippet showcasing attempts to incorporate the image:

credits: {
    enabled: true,
    text: 'Highcharts.com',
    href: 'http://www.highcharts.com',
    position: {
        align: 'right',
        x: -10,
        verticalAlign: 'bottom',
        y: -5
    },
    style: {
        cursor: 'pointer',
        color: '#909090',
        fontSize: '10px',
        backgroundImage: 'url("/image/example")'
    }   
}

Accompanied by the related JavaScript code designed to handle the display of the credits information:

if (credits.enabled && !chart.credits) {
        creditsHref = credits.href;
    chart.credits = renderer.text(
        credits.text,
        0,
    0
    )
    .on('click', function () {
        if (creditsHref) {
            location.href = creditsHref;
        }
    })
    .attr({
        align: credits.position.align,
        zIndex: 8
    })
    .css(credits.style)
    .add()
    .align(credits.position);
}

Answer №1

UPDATE 2:

To begin with, adjust the numbers to match your specific requirements (width, height, x, y, etc). It seems like you have also altered your chart type. To revert back to a spline chart, use the following code:

   chart: {
       renderTo: 'your-container-id', // ID of chart div
       type: 'spline', // specify chart type
....

Ensure that the chart does not resize when the browser window is resized by setting the width attribute:

<div id="your-container-id" style="width:1000px;"></div>
, or set it to the desired size.

Also, adjust the right margin to include negative space on the right side of the chart:

chart: {
 renderTo: 'your-container-id', // ID of chart div
 type: 'spline', // specify chart type
 margin: [ 50, 150, 100, 80 ], // top, right, bottom, left. leaves 150px of negative space on the right side of the chart. adjust as necessary
....

Lastly, position the image on the right side of the chart:

chart: {
 renderTo: 'your-container-id', // ID of chart div
 type: 'spline', // specify chart type
 margin: [ 50, 150, 100, 80 ], // top, right, bottom, left. leaves 150px of negative space on the right side of the chart. adjust as necessary
 events: {
   load: function() {
     this.renderer.image('http://upload.wikimedia.org/wikipedia/commons/e/ec/Happy_smiley_face.png', 900, 105, 100, 100).add(); // x=900px moves the image off the chart (approximately width of div minus right margin). Adjust as needed.
       }
     }   
....

If resizing of charts is required, a function needs to be written to reposition the graphic upon resize. However, that topic is for another discussion.

If the provided solution does not align with your intentions, please provide more details about the desired outcome.

UPDATE 1:

Adding backgrounds to the credit section of the chart is not feasible. Typically, I disable it unless branding with our company name and link is required. Consider utilizing the legend functionality or incorporating a custom image with a wide margin instead.

Refer to this modified fiddle from the highcharts site to visualize the concept: jsFiddle Link
In summary:
Include a standard legend in the chart with show/hide capability:

 legend: {
  layout: 'vertical', // vertically stacked legend. Can also be horizontal and positioned at the bottom for a sleek linear legend
  backgroundColor: '#FFFFFF',
  align: 'left',
  verticalAlign: 'top',
  x: 380, // moved to the right side of the chart
  y: 200, // dropped down by 200px
  floating: true, // positioning enabled
  shadow: true
 },

Add a background image aligned to the far right:

 chart: {
   renderTo: 'container',
   type: 'column',
   margin: [ 50, 150, 100, 80 ], // wide right margin to accommodate image outside the chart
   events: {
     load: function() {
        this.renderer.image('http://upload.wikimedia.org/wikipedia/commons/e/ec/Happy_smiley_face.png', 400, 105, 100, 100).add(); // x=400px shifts the image off the chart
   }
 }   
}

NOTE: The width of the chart container is set to 500px.

I trust this sheds light on the matter.

ORIGINAL ANSWER:

Last week, I updated all our company charts to utilize highcharts. Employ the following code snippet for incorporating a background image:

chart: {
            renderTo: 'container',   // where should the chart be placed?
            type: 'column',   // what type of chart is being used?
            margin: [ 50, 50, 100, 80 ],   // margins between the outer edge and plot area
            events: {
                load: function() {
                    this.renderer.image('http://www.domain.com/images/logo.jpg', 150, 105, 545, 141).add();  // add image(url, x, y, w, h)
                }
            }
        },

The parameters for the image are as follows: image(url, x, y, width, height);

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

Modify the appearance of a single component among a collection of 20 instances

I'm looking to dynamically change the background color of my components based on the colors of the images inside them. Each component should have its own unique color, but currently all 20 instances on the page are getting the same color. I've tr ...

Assistance with Javascript to optimize page performance

As a newcomer to Javascript, I acknowledge that my question might be basic. I have a JS script in the head of my application that is causing a delay in page loading time on examplepage.php. The script is as follows: <script type="text/javascript"> $ ...

Is there a substitute for image cropping aside from the CSS clip property?

Looking to create an image gallery where thumbnails are cropped to 150px x 150px, but struggling with non-square rectangular images of various sizes. Adjusting width and height distorts the images. Are there alternative CSS or jQuery options for cropping ...

Safari is not properly handling element IDs when used in conjunction with React

I am currently in the process of building a straightforward single-page website utilizing React. At the top of the page, there is a navigation bar that contains links to various sections of the site: <li><a href="/#about">About u ...

Using JSTL with jQuery or JavaScript

I am trying to send array elements from my Java code to a JSP page. The goal is for the array elements to be displayed on the page when a button is clicked. I have attempted to use the JSTL forEach tag within JavaScript or jQuery, but unfortunately, it do ...

What is the Proper Way to Import Three.js Modules in a Vue Application?

My goal is to utilize three.js for displaying a gltf file. To achieve this, I need to import the GLTFLoader module from the three.js node package. As per the documentation, the correct way to import it is: import { GLTFLoader } from 'three/examples/ ...

How can I ensure the MatBottomSheet aligns perfectly with the top toolbar?

If we intend for the MatBottomSheet to appear with its top aligned perfectly against the top toolbar, what is the most effective approach to achieve this? Refer to the demo provided in the documentation. View the demonstration here In this stackblitz ex ...

Animations in Phaser do not function properly on touch screen devices, although they work seamlessly on desktop computers

In my phaser.js game, I have a variety of animations set up: this.anims.create({ key: 'catchingUp', frames: this.anims.generateFrameNumbers('android', { start: 0, end: 4}), frameRate: this.frameSpeed * 6, ...

Trouble with CSS Class Showing Up Only When Hovered

My goal is to make the .panel-text element visible only when a user hovers over the panel. I attempted to use the overlay CSS class, but I encountered issues where the text either wouldn't show at all or would always be displayed. Here is what I have ...

Navigating with Google Maps version 3 directions

Currently in the process of creating a new Google maps feature for my website, moving away from using v2. Everything has been smooth sailing up until the final step...after requesting directions on the map, there should be a visual line indicating the ro ...

Issue with a variable within an *.ejs file

Currently, I am following a guide found at this link, and everything is working smoothly except when I encounter an error on the login screen: ..... 7| >> 8| <% if (message != null) { %> 9| <%= message %> 10| <% } %> 11| message ...

What is the best way to show checkbox selections based on my database structure?

Two variables, one for checkboxes and the other for checked values are causing an issue in displaying them from controller to view. The code to handle this in the controller is as follows: $scope.infoParticipant = functionThatGetsParticipants(); ...

What sets apart a React component from a function-as-component in React?

React is really confusing to me right now. Take this simple react component for example: export default function Foo(){ return( <div> <div>some text</div> </div> ) } I want to add a child compone ...

Updating ReactJS state from a third-party JavaScript file when the page loads

I'm currently attempting to handle this task within the componentWillMount() function of a React component class. const script = document.createElement("script"); script.src = "https://apis.google.com/js/client.js"; script.async = true; ...

What could be causing the error that appears when I execute npm run build command?

I am fairly new to this and feeling quite lost. It seems like I have made some mistakes which are causing me trouble now. My main goal is to run the npm run build command for my React.js project so I can deploy it. However, when I try to execute npm run bu ...

Taking steps when a number is enclosed within a span

Testing a simple code with similar action to what I want. Apologies for any language errors, hoping to be understood :-) The HTML code snippet: <div class="pagination"> <a href="#" class=""><span>1</span></a> <a href=" ...

Conceal object after a brief pause

Why does the element hide immediately instead of slowly fading out? I can't figure out why it doesn't first display the "P" tag and then gradually hide it. Please help me solve this issue. var step = 0.1; var delay = 90000; var displayMe = fun ...

Achieving a bold border on top of an image without altering the image's dimensions

I'm in need of Photoshop-like selection functionality, but when I add a border to the enclosing div that holds the image, the image ends up smaller by twice the thickness of the border. How can I fix this issue? I have attempted a solution by adding ...

The useState setFunction does not alter on OnClick events

My useState element is causing issues because the function doesn't get called when I click on it. I've tried multiple solutions and debugging methods, but it seems like the Click event isn't being triggered no matter what I do. const [moda ...

`How can I dynamically hide a collapsible Bootstrap navbar with a click event in a React.js application?`

Hey there! I've managed to create a collapsible navbar with Bootstrap 5 that is working smoothly, but now I want it to automatically close when the user clicks on a link. Is there a way to achieve this in React? Thanks in advance! React.JS navbar : ...