Issues with displaying graphs using Angular.js, Highcharts, and Phantomjs PDF printer has been encountered

I am facing a peculiar issue with my Angular.js application that uses Highcharts for graph rendering. The application needs to support PDF printing, which is achieved through our company's Phantomjs PDF service.

Graphs are generated using a custom directive. Here is a simplified version of the code:

app.directive('metricsChartMulti', [
    function () {
        return {
            ...
            link: function postLink(scope, element, attrs) {

                ...

                // Plot data after loading
                scope.$on('DATA_LOAD_SUCCESS', function() {

                    var chartOptions = {
                        series: scope.series
                        ...
                    };

                    var chart = new Highcharts.Chart(chartOptions);

                });
            }
        }
    }
]);

The series data (scope.series) are prepared in the controller and added to the scope. Everything works perfectly in the browser without any errors. However, when I use the Phantomjs2-based PDF creation service, the graphs do not render in the resulting PDF file.

I have checked the code thoroughly but couldn't find any issues. I followed common best practices for Angular framework while developing the app. After extensive debugging, I discovered that replacing scope.series with static mock data results in correct PDF plot generation.

This change is not visually noticeable in browsers like Chrome and Firefox.

I also tested generating PDFs directly from the Highcharts website, and they were created correctly. This indicates that there might not be an issue with our company's PDF service.

Any suggestions on how to resolve this unusual dilemma? Thank you.

Answer №1

After much trial and error, what ultimately resolved the issue was creating a complete duplicate of the scope.series object inside the directive.

var seriesCopy = JSON.parse(JSON.stringify(scope.series));

It may not be the most elegant fix, but at least it gets the job done for now.

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 a unique element within an array stored in the state using Redux toolkit

I'm currently attempting to modify a property of an object within an array stored in my state. export const changeStatus = createAsyncThunk('changeStatus', async (arg) => { const todo = arg const response = await axios.put(`${URL} ...

Validation of textfields using React.js

Currently, I am working on implementing a validation feature in ReactJS. Specifically, I have a field named "name" and my requirement is that every time a name is entered, it must be equal to or greater than 2 characters. The validation works fine when t ...

Utilize datetime values in chartjs ajax for data visualization

I'm currently working on creating a chart using chart.js. I have php code that retrieves datetime data through an ajax call. However, the chart is not displaying any data and there are no visible errors. I've checked the php code using console.lo ...

"Error encountered: 'require' is not defined in the bundled JS file for

Recently, I decided to try my hand at Django and ReactJS. While attempting to compile a simple JSX code to JS, I followed this tutorial: . However, I encountered an error that prevented it from working. I then resorted to using npm run dev to compile the c ...

Can modifications be made to a page's source content variable using Ajax?

Can modifications be made to the source content of a page through Ajax loaded by a jsp include in the main jsp? If not, is it possible to refresh only that portion of the page (the jsp that loads some of the content) and have a portion of the content in t ...

Issue with radio button click event not triggering

Whenever I click on a radio button, I want to call a function, but for some reason, it's not working as expected. I found this fiddle that demonstrates exactly what I want, but when I implement it in my code, it doesn't work. Here's a snipp ...

Score increase in a jQuery based quiz

Currently, I am in the process of developing a jQuery quiz where I have successfully been able to calculate the total value of each answer. However, I am now looking to enhance the quiz by incorporating a function that will update specific variables with p ...

Dynamic, AJAX-driven content is experiencing a 200 status code

Is it necessary for a single-page website, which dynamically loads content via ajax and utilizes browser session history stacking, to return a "200 Status" for each successful state change? The core code of my website is as follows: $(document).on('c ...

Validating various Google Sheet tabs in real-time

I am currently working on a script for validating localization tests in Google Sheets and I have run into some challenges with the logic. The main goal of the script is to 1) Go through all tabs, 2) Identify the column in row 2 that contains the text "Pass ...

Formik's handleChange function is causing an error stating "TypeError: null is not an object (evaluating '_a.type')" specifically when used in conjunction with the onChange event in DateInput

When using the handleChange function from Formik with the DateInput component in "semantic-ui-calendar-react", I encountered an error upon selecting a date. https://i.stack.imgur.com/l56hP.jpg shows the console output related to the error. AddWishlistFor ...

Creating PDF Files Using JSreport and Node.Js

Looking to create a PDF file on a Node.js server using HTML and CSS code? I recently set up JSreport on a local Nginx server and it appears to be the solution I was seeking: just input the HTML and CSS code, and voila - a PDF file is generated. https://i ...

Tips for crafting effective error messages to communicate with users

One of the biggest challenges I face is crafting clear error messages for clients in case of errors. A typical scenario involves using Axios and a third-party API to fetch data, requiring appropriate error handling for both. Axios' error handling doc ...

Encountering an Uncaught TypeError when attempting to set properties of null with useRef

I've been working on an app that requires access to the user's device camera in order to display live video on the screen. I've managed to achieve this by utilizing a video HTML Object and setting the media stream as its srcObject. Everythin ...

Is It Possible to Extract a Hidden Document Value from a Web Browser Using IWebBrowser2 in LabVIEW?

After hours of combing through the internet, I've come up empty-handed in my quest to find information related to my current project. I've created an HTML document that gathers user data and stores it in a JavaScript array. This array is then com ...

Trigger the C# Click event with JavaScript fire function

Hi there, I could use a bit of assistance. My goal is to allow users to log in by hitting the "Enter" key on their keyboard. While I've successfully detected when the "Enter" key is pressed in my JavaScript code, I'm struggling with how to call m ...

The functionality of images and links is compromised when they are assigned as values to properties within a JSON object

My images and links are not working, even after declaring them globally. When I write the src directly into src, everything seems fine but the alert pops up with the same URL and img src. Can anyone help? var combo0; var combo1; var combo2; var combo3; ...

Creating a test suite with Jasmine for an Angular ui-grid component compiled without using $scope

I have encountered an issue while using $compile to compile a ui-grid for Jasmine testing. Initially, everything worked smoothly when I passed $scope as a parameter to the controller. However, I am now transitioning to using vm, which has resulted in $comp ...

Express is encountering a non-executable MIME type of 'text/html' with Webpack

My express application setup is as follows: const express = require("express"); const app = express(); const server = require("http").Server(app); const path = require("path"); const port = process.env.PORT || 5000; app.use(& ...

Transforming Material UI into a class-based component

How can I transform a React function into a class? I'm having trouble understanding how to adjust const { classes } = props; in a function to work within a class. You can find an example button function from Material UI here: import React from &apos ...

Fetching information with request query parameters in Node.js

Working on implementing email verification using nodemailer for user sign-ups. The process involves sending out an email containing a link (usually something like localhost:3000/verify/?id=##). After the user clicks the link, I can see that a GET request ...