Jump to content
JChartFX Community
  • 0

NULL data in line chart


JohnDeery

Question

Good day,

I'm trying to set up a line chart where I'm showing a change in data over time by person, but I want to account for if there is no data registered (which would show a break in the line). I'm using PHP on the back-end, so I create my array where I initialize each person to NULL, then when I loop through I fill in for each person that does have data. The problem is, if the first person in the array that makes it back to the front-end has null data, then the chart won't build... I just get a default "Series1" label and a straight line across 0. If I have people that have some data, and then others with nulls it works fine, but I'm trying to figure out if there is a way around this, or if there is another value I can pass in to show "no data" so I get the breaks in the line without resorting to using a 0 value (which would be a good thing in this case, higher numbers are bad so 0 would be a false positive).

Thanks for any help/ideas

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 1

There are 2 things in play in your code

1) There is a bug that will prevent you from using a field whose first value is null, we have fixed it internally so we expect to have a new build soon

2) Even with that bug fixed, our behavior to automatically use fields as values to be plotted or labels is to check the value for all the fields for the first object in the array, because of this the automatic detection will not work in your scenario. and you will have to explicitly tell us the fields you want to use, e.g. add this code before setDataSource

        var fieldMap;
        var fields = chart1.getDataSourceSettings().getFields();

        fieldMap = new cfx.FieldMap();
        fieldMap.setName("john smith");
        fieldMap.setUsage(cfx.FieldUsage.Value);
        fields.add(fieldMap);
        fieldMap = new cfx.FieldMap();
        fieldMap.setName("jane doe");
        fieldMap.setUsage(cfx.FieldUsage.Value);
        fields.add(fieldMap);
        fieldMap = new cfx.FieldMap();
        fieldMap.setName("paulie walnuts");
        fieldMap.setUsage(cfx.FieldUsage.Value);
        fields.add(fieldMap);
        fieldMap = new cfx.FieldMap();
        fieldMap.setName("Date");
        fieldMap.setUsage(cfx.FieldUsage.XValue);
        fields.add(fieldMap);
 

There is a workaround which should work on your bits which is to replace the value for any null field in the first object in your data array with cfx.Chart.Hidden, e.g. if your data was declared like this, you would get the expected result

    var items = [{
        'john smith' : cfx.Chart.Hidden,
        'jane doe' : 30,
        'paulie walnuts' : 50,
        'Date' : '2018-03-01'
        },
        {
        'john smith' : 50,
        'jane doe' : 20,
        'paulie walnuts' : 10,
        'Date' : '2018-03-02'
        },
        {
        'john smith' : 20,
        'jane doe' : 10,
        'paulie walnuts' : 60,
        'Date' : '2018-03-03'
        }];
 

Regards,

JuanC

 

 

 

Link to comment
Share on other sites

  • 1

Can you post a small client side script with hardcoded data that reproduces your issue, e.g.

    chart1.setDataSource([{"Value":10, "Label":"January"},{"Value":12, "Label":"February"},{"Value":18, "Label":"March"},
                          {"Value":6, "Label":"April"}, {"Value":8, "Label":"June"},{"Value":13, "Label":"July"},
{"Value":24, "Label":"August"},{"Value":21, "Label":"September"},{"Value":19, "Label":"October"}]);
 

Regards,

JuanC

 

Link to comment
Share on other sites

  • 0

Sure. First, here is a working version:

http://jsfiddle.net/L5fh0tsq/7/

Here is that same code with the second "Jane Doe" set to null, you'll see that you get points at date 1 and 3, but nothing at 2, which is the wanted and expected behavior:

http://jsfiddle.net/66rhnp4x/2/

And finally the broken version:

http://jsfiddle.net/qjLxv720/2/

In this case, I'm just getting the whole row rejected instead of the weird "Series1", but the result is still the same. Interestingly, if you change the first value in the first array (john smith) back to a number and then change the first "jane doe" to null, it works as I would expect, so it only seems upset if the very first value is a null

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