Adding fresh data to a C3.js line graph

I am attempting to dynamically update a C3.js line chart using a function that retrieves a set of x and y values from a database. The function I want to use for inserting the data is:

function insertGraph(yAxis, xAxis, Header) {
    setTimeout(function () {
        console.log("starting");
        chart.load ({
            bindto: "#graph",
            xs: {
                'y':'x'
            },
                columns: yAxis, xAxis   
        });
    }, 100);
}

The input data for the function looks like this: yAxis:

["y", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

xAxis:

["x", 0, 131.35, 26971.3, 27044.75, 27351.4, 27404.483333333334, 27419.416666666668, 33128.96666666667, 33549.13333333333, 34049.48333333333, 77464.26666666666, 77609.71666666666, 174171.85, 259166.98333333334]

Header:

MakeModeChange #just a string

It seems there may be an error in my approach, any assistance would be greatly appreciated

Answer №1

If you ever find yourself needing a solution, I was able to resolve my issue by tweaking the "columns" section (it must be enclosed in square brackets []). Below is the corrected code for your reference:

function generateChart(yAxis, xAxis, Title) {
    setTimeout(function () {
        chart.update ({
            bindto: "#graph",
            xs: {
                'y-axis':'x-axis'
            },
            columns: [
                yAxis,
                xAxis
            ]   
        });
    }, 100);
}

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

Having trouble accessing functions in Typescript when importing JavaScript files, although able to access them in HTML

Recently, I started incorporating TypeScript and React into my company's existing JavaScript code base. It has been a bit of a rollercoaster ride, as I'm sure many can relate to. After conquering major obstacles such as setting up webpack correc ...

Could there be a more efficient method to enable support for all video formats?

I have a case statement in my video validation function that checks for specific file extensions of video formats. However, I am wondering if there is a shorter way to write the code in order to allow all video formats instead of creating a long list of al ...

Highlight text when the user is scrolling the page - using JQUERY

Can anyone suggest a way to dynamically underline text as the user scrolls down a webpage? The underline should only be visible while the user is scrolling. I've experimented with animate.css and other plugins, but haven't been able to achieve th ...

When interacting with the iframe in an Ionic3 app, it suddenly crashes

Greetings! I have integrated a flipping book URL inside an iframe: <ng-container> <iframe [src]="eUrl" id="flipping_book_iframe" frameborder="0" allowfullscreen="allowfullsc ...

Transfer information via query or retrieve from storage in Vue

When considering sending a data variable to another component, is it more efficient to send it via query using a router or save the data in-store? Which method would be more optimal? router.replace({ name: 'routerName', query: { param ...

JavaScript for beginners: show a specified amount of search results and insert a loading indicator at the end

Currently, I have a website that retrieves data from my database using a PHP query. However, the issue I am facing is that there are over 300 entries in my database, resulting in an excessively long displayed page. My main question: How can I restrict ...

Discover the basics of incorporating libraries using npm

As a beginner in JavaScript, I am looking to incorporate moment.js or another library into my project. However, I am unsure of how to properly set up my project so that I can import from the library. Here is how I have structured my HTML: <!DOCTYPE html ...

Is there a way to determine the actual time or percentage completion of a file upload using Telerik RadUpload?

Utilizing the Telerik upload file control with manager is a key component of my project: <telerik:RadUpload ID="RadUpload" Runat="server" MaxFileInputsCount="5" /> <telerik:RadProgressManager ID="RadProgressManager" Runat="server" /> For clie ...

Understand which form has been submitted

I have eight Forms in a page (Form0, Form1, Form2 and so forth). Each form, when submitted, sends data to ReassignPreg.php using JavaScript, which then searches for the data in the database and returns it as JSON. The corresponding divs on the page are the ...

What could be causing my function to not successfully retrieve elements based on their text content?

A function called matchTagAndText is designed to take two arguments: a selector and text, checking if any matched elements contain the specified text. The function code is as follows: function matchTagAndText(sel, txt) { var elements = document.queryS ...

Tips for dynamically assigning unique IDs to HTML form elements created within a JavaScript loop

let count = 0; while (count < 4) { $('#container').append("<div><input type='textbox' class ='left' id='left-${count}'/><input type='textbox' class ='right' id=' ...

Tips for sending a property to a function that is imported and produces a component in React

I need help figuring out how to pass an argument back to my component library that is imported in a parent app as a dependency. The specific issue arises when I am trying to implement a brand concept in the theme object. The goal is to switch the theme bas ...

The .get function is functioning properly during development, but encountering issues in the production environment

Here is the scenario: while running my server on node.js locally, the client code successfully retrieves data from the server. However, upon pushing the code to the live server, the client receives a /getSettings 500 (Internal Server Error). The main index ...

A guide on removing an element from a state array in a React functional component for a To-Do List application

I need help making a to-do list item disappear when clicked. The deleteHandler method is not working as expected. Can anyone provide logic on how to filter out the clicked item? import React, { useState } from 'react'; const ToDoList = () => ...

How to enhance mouse tracking beyond browser window boundaries in Three.js and across various page elements

I'm facing an issue with my three.js scene where I have buttons positioned on top and off to the side of the scene. When you click and drag to spin the camera, the spinning stops when dragging over the buttons or outside the window. I am using three.j ...

When you click on the submit button, it triggers the associated event

I have multiple text input fields where pressing the enter key should move focus to the next field. After reaching the last text input, I want the focus to be on the submit button without triggering its click event until the user presses enter again. The c ...

Transitioning to the Bootstrap library from the jQuery library with the use of several image modals

After coming across this specific question about implementing multiple image modals on a webpage, I noticed that it primarily focused on javascript and jQuery. However, my project involves utilizing the latest version of Bootstrap, so I'm curious if t ...

In Snowflake, SQL error handling block fails to execute

Implementing error handling in Snowflake using a Try Catch block has been my focus. I've enclosed SQL queries within JavaScript for this purpose. However, upon executing the query, I noticed that it skips the Try Catch block and directly executes the ...

Enter your text in the box to search for relevant results

I need assistance with a code that allows me to copy input from a text box to the Google search box using a copy button. Upon pressing the Google search box button, it should display the search results. Here is the code I have been working on: http://jsf ...

Tips on avoiding a page reload following a form submission using JQuery

Currently developing a website for my app development project, I've encountered an unusual issue. Utilizing some JQuery to transfer form data to a php page called 'process.php' and then add it to my database. The strange part is that the pa ...