Revise the line graph

Currently, I am utilizing dimple js and have a line chart code. However, there seems to be an issue with the event I set up - whenever a button is clicked, the chart should redraw using chart.draw(), but this function doesn't seem to work. Any insights on where the problem lies would be greatly appreciated. html :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
<button id="test">Click Me</button>
<div id="chartContainer" class="chart_style"></div>
</body>
<script src="js/d3.js" charset="utf-8"></script>
<script src="js/dimple.js"></script>
<script type="text/javascript">
    var svg = dimple.newSvg("#chartContainer", 600, 400),
            data = [
                { "Value" : 10, "Year" : 2009 },
                { "Value" : 5, "Year" : 2010 },
                { "Value" : 4, "Year" : 2011 },
                { "Value" : 7, "Year" : 2012 },
                { "Value" : 10, "Year" : 2010 },
                { "Value" : 50, "Year" : 2020 },
                { "Value" : 40, "Year" : 2015 },
                { "Value" : 100, "Year" : 2014 },
                { "Value" : 200, "Year" : 2014 }
            ];
    var chart = new dimple.chart(svg, data);
    var x = chart.addCategoryAxis("x", "Year");
    x.addOrderRule("Year");
    var y = chart.addMeasureAxis("y", "Value");
    chart.addColorAxis("Value", ["green", "yellow", "red"]);
    var lines = chart.addSeries(null, dimple.plot.line);
    lines.lineWeight = 4;
    lines.lineMarkers = true;
    chart.ease = "bounce";
    chart.staggerDraw = true;
    chart.draw(2000);
    d3.select("#test").on("click", function() {
     ///here is the problem
        data = [
            { "Value" : 10, "Year" : 2009 },
            { "Value" : 5, "Year" : 2010 },
            { "Value" : 4, "Year" : 2011 },
            { "Value" : 50, "Year" : 2020 },
            { "Value" : 40, "Year" : 2015 },
            { "Value" : 120, "Year" : 2014 },
            { "Value" : 150, "Year" : 2011 },
            { "Value" : 500, "Year" : 2018 },
            { "Value" : 250, "Year" : 2015 },
            { "Value" : 200, "Year" : 2014 }
        ];
        chart.draw(1000);
    });
</script>
</html> 

Answer №1

To update the data linked to the chart, make sure you modify the chart.data attribute:

chart.data = [ ... ];

It's important to note that simply reassigning the data variable in your code will not affect the dimple chart. For a complete demonstration, check out this link.

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

Using jQuery, it is possible to automatically generate a new HTML input element and access it within

My issue is: I am facing a problem with a dynamically generated table on my page using ajax-jquery My table consists of 3 <td> elements: 1 for name and 2-3 for checkboxes representing parameters I have set up an event for all input checkboxes to d ...

JSX refusing to display

Currently, I am enrolled in an online course focusing on React and Meteor. Despite successfully registering a new player in the database upon hitting the submit button, the client side fails to display the information. Upon checking the console, the foll ...

Building a versatile and interactive table using AngularJS with data sourced from a

I am currently working on creating a dynamic table using Angular JS to display data received from a Spring Rest Service. Here is the code snippet I have been working with: // JavaScript Document var app = angular.module("SDLC", []); app.config([&apos ...

Transforming a JSON file that has been previously converted to an Observable into a TypeScript map within an Angular application

There is a json data file named dummy, with the following structure: [ {"key":"KEY1", "value":["alpha","beta","gamma"]}, {"key":"KEY2", "value":["A","B","C"]}, {"key":"KEY3", "value":["One","Foo","Bar"]} ] The goal is to convert this json f ...

What is the best way to update the state while invoking a component?

Just starting out with react and already hitting a roadblock. I've created an Article Topper component that features a logo, title, and share buttons, which is repeated throughout the site above each article. The issue I'm facing is updating the ...

Error with the login component in React.js (codesandbox link included)

Hey there! I'm a beginner programmer and I recently dove into a tutorial on creating a Login Form. However, I've run into a few issues along the way. Overview of My Project: The login form I'm working on was built using create-react-app. T ...

What is the best way to display JSON within a partial?

Within my Rails app, I have implemented a JavaScript graph. Whenever I click on a circle in the graph, it displays the name of the corresponding user. Now, my goal is to retrieve additional information from the related database table based on this user&apo ...

Employing a break statement after the default case within a switch statement even when the default is not

According to a tutorial from w3schools that discusses switch statements, it is advised: If the default case is not the last case in the switch block, it is important to remember to end it with a break statement. However, the same tutorial also explains ...

Extracting JavaScript variable data to PHP using Ajax technology

I've been trying to save latitude and longitude values in PHP variables, but I'm having trouble. Here is the code I'm using. Can anyone please help me figure out why these values are not being stored in PHP variables: Code: <!DOCTYPE h ...

I'm seeking guidance on handling complex relationships with Mongoose. Please provide a specific challenge example for a quick solution. Thank you

While I am skilled in using sequelize with node, angular, express etc., I am just beginning to delve into the M part of the MEAN stack by learning mongoose. However, I'm unsure of MongoDB's capabilities when it comes to organizing data in the dat ...

The NWjs iteration of Bad Time Simulator is having trouble playing background music

Recently, I came across an interesting online game and decided to try my hand at modding it. However, I faced challenges while modifying the source code on Github - the pages took too long to load and my browser cache seemed impossible to clear. In a ...

Execute a series of promises sequentially, ensuring that each subsequent promise is only run after the previous one has been resolved

I am in the process of creating a script that will execute all found .sql files within a designated folder one by one. The objective is to halt the execution if any one of the scripts fails. The structure of my folders is as follows (and I initiate the scr ...

Tips for modifying the response of an ExpressJS server following a timeout on a POST request

Currently, I'm in the process of creating a server using Node.js and ExpressJS. The issue arises when the client sends a POST request instructing the server to control an external device's movement either up or down. My goal is for the server t ...

A guide on efficiently traversing a disk directory, recursively fetching all paths in relative format, and converting them into a JSON stream with node.js

My goal is to traverse a directory tree and store it in a JSON file using node.js with the following approach: Open specified directory Convert paths into a relative format. For example: Directory: C:/test { {"C:/test folder 1": [ {"folder 1": ["fil ...

Seeking assistance with coding a beginner-level Google Chrome extension

Currently, I am working on developing a basic Google Chrome extension with 2 or 3 browser actions. I have been using Selenium IDE to capture the necessary steps in Firefox that I need for my project. However, I am unsure of how to translate these recorde ...

What is the best way to utilize moment.js for adding days while excluding weekends?

I have a requirement to set a default follow-up date that is two days ahead of the current date. The existing code for this functionality is as follows: const Notify = moment().add(2, 'days').toDate(); Now, I need to modify this code to exclude ...

Searching for elements by tag name in JavaScript

Recently, I attempted to create JavaScript code that would highlight an element when a user hovers their cursor over it. My approach involves adding an event listener to every child within the first "nav" tag in the current document: let navigation = docum ...

Is there a way to modify the CSS or add custom styling within an iframe form?

Currently I am working on the following page: , where an embedded javascript form called infusionsoft (iframe form) needs to be made responsive at the request of my client. I'm wondering if there is a way to override the css or inject custom styles i ...

filling out a form with data retrieved through an ajax request

After retrieving JSON data from an MVC controller, I am attempting to populate a form with this data but encountering difficulties. The returned data consists of only one row with three properties. Despite confirming that the data is being returned success ...

What could be the reason behind getting a useLayoutEffect error when using renderToString to render a Material-UI component?

Currently, I am utilizing React version 16.12.0 along with @MaterialUI/core version 4.8.1. The challenge I am facing involves creating a custom icon for a React Leaflet Marker. The icon in question is a Fab component sourced from Material-UI. In order to ...