Jump to content
JChartFX Community
  • 0

Can I trigger an annimation?


brammh

Question

Hi,

I'm using: "myChart.getAnimations().getLoad().setEnabled(true);" to enable animations on my combined chart. This looks nice.
Ocasionally my page is updating chart data: "myChart.setDataSource(JSON.parse(data));"

After I updated the data source, new data is shown in my chart as expected. However it would be nice if this could be done with an animation.

Is there a way in achieving this?

thanks,
bram 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

There are 2 ways of doing this, first there is a feature of animations called DataChange which should allow you to animate the data changes in the chart, this works if you only change the data and also if the "shape" of the data (number of series, number of points, etc.) does not change, I noticed there might be a bug when using setDataSource so you might have to change the values independently, e.g.

function doInitialize() {

    chart1.getAnimations().getLoad().setEnabled(true);

    chart1.setGallery(cfx.Gallery.Bar);

    var axisY = chart1.getAxisY();

    axisY.setMin(0);

    axisY.setMax(100);

    var data = [{"Year":"2012", Value:25}, {"Year":"2013", Value:45}];

    chart1.setDataSource(data);

    chart1.getAnimations().getDataChange().setEnabled(true);

}

function changeData() {

    chart1.getData().getY().setItem(0, 0, 65);

    chart1.getData().getY().setItem(0, 1, 15);

}

The second approach works even if the shape of the data changes but will animate from 0 instead of the current values, remove the getDataChange().setEnabled line from the initialization and then use Animations.Reset as follows

function changeData()

{

    var data = [{"Year":"2012", Value:65}, {"Year":"2013", Value:15}];

    chart1.setDataSource(data);

    chart1.getAnimations().reset();

}


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...