Jump to content
JChartFX Community
  • 0

Persisting changes made using the new menu


David.Harris

Question

I have a system that generates a chart on a page. The user can then update the chart settings using the new menu that is supplied in the latest release. Is there a way to retrieve the settings that have been set by the user so I can persist them somewhere and restore the page as the user configured next time the user returns to the page?

 

TL;DR - Can I save menu changes?

  • Like 1
Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

Currently there is no way, we have worked on enabling persistence and there is an extra script (jchartfx.persistence.js) that currently has the code so that a chart can read all its settings from a json object, but we do not support saving the current settings yet.

 

We will consider adding support for this for future builds.

 

JuanC

Link to comment
Share on other sites

  • 0

Using this community forum is the preferred way to submit feature requests. If there is any other feature you would like to see added to the product, besides persisting user changes, please submit it on a new post and we will gladly review the possibility to include it in a future build.

---

The jChartFX Team

Link to comment
Share on other sites

  • 0

We are almost ready to push this functionality on the unstable build. The way it will work (suggestions are welcome) would be as follows

 

1) Besides coreVector you will need to include the userInterface and persistence scripts

 

2) After you create and customize your chart you would do the following in order to save the current settings as the baseline as well as be notified of any changes on the UI (you could ignore the uiNotify call if you plan to save changes manually)

 

chart1.recordBaseline();

chart1.uiNotify = onChartChange;
 
3) After the recordBaseline call you should incorporate the end-user changes, in this sample we are using localStorage but in order to save these personalizations on the server, you would probably connect to SQL (or any other storage API) on the server to generate a JSON that will be loaded on the client, note that to avoid the chart painting twice, you would not want use XMLHttpRequest but instead make sure the end-user customizations are sent back on the HTML page rendered by the client
 
var userChanges = localStorage.getItem("chart");
if ((userChanges !== undefined) && (userChanges != null)) {
    // alert(userChanges);
    chart1.loadJson(JSON.parse(userChanges));
}
 
4) In the function invoked by our UI (or in the code that saves the user changes manually)
 
function onChartChange()
{
    var json = this.changesFromBaseline();
    var text = JSON.stringify(json);
    localStorage.setItem("chart", text);
    // alert(text);
}
 
In a server approach you would use XMLHttpRequest (or ajax if you are using jQuery) to send the JSON string to the server.
 
These bits should be available soon on the unstable channel. Please let us know if this approach would work on your scenarios.
 
JuanC

post-2107-13939745470425_thumb.png

Link to comment
Share on other sites

  • 0

So changesFromBaseline() returns a diff of the settings since the last call to recordBaseline()?  Interesting approach. :)

 

Could you also implement a function which returns the complete settings (as if recordBaseline() hadn't been called?)

 

Thanks,

mike

Link to comment
Share on other sites

  • 0

The reason to have a baseline is that 1) your code will make some changes to the chart and 2) if you are using a motif, it might make some changes to the chart. If you include these changes when serializing the user changes, it might make it impossible to change motifs at a later time.

 

There is a method already in chart called saveJson. If you invoke it without parameters it will return a JSON that contains the serialization of the chart but only the values that are different than the default. If you pass an empty object, e.g. chart1.saveJson({}), it will return the complete serialization of the chart (all members will be serialized).

 

There is also a method called loadJson that receives a JSON object and reads the chart settings from it.

 

Both of these (loadJson and saveJson) are implemented in the persistence js

 

JuanC

Link to comment
Share on other sites

  • 0

The saveJson function was only added in the latest unstable build (5666). We should be publishing documentation for these 2 methods soon.

 

To be notified of UI changes by the user you would set the uiNotify to a function as in my previous post. We might rename this event before pushing the changes to the stable channel (probably changedByUser)

 

Regards,

 

JuanC

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...