Jump to content
JChartFX Community
  • 0

What decides if a series should be drawn or not?


Question

Hi,

 

It seem like series not present in the first time step will not be rendered at all when feeding the chart with JSON.

For example, with the JSON below, only the the series MY-HOST will be present in the chart.

Is there any way to to make sure all series are included and drawn in the chart, even with an unreliable JSON like this?

 

Thanks! 

 

Sample JSON 

[

    {

        "Date": "2013-11-12 19:45",

        "MY-HOST": 66

    },

    {

        "Date": "2013-11-12 19:46",

        "MY-HOST": 48

    },

    {

        "Date": "2013-11-12 19:47",

        "AVG": 27592,

        "COMPLETED": 1,

        "ABORTED": 0,

        "MY-HOST": 36

    },

    {

        "Date": "2013-11-12 19:48",

        "AVG": 10142,

        "COMPLETED": 2,

        "ABORTED": 0,

        "MY-HOST": 28

    },

    {

        "Date": "2013-11-12 19:49",

        "AVG": 3201,

        "COMPLETED": 1,

        "ABORTED": 0,

        "MY-HOST": 31

    },

    {

        "Date": "2013-11-12 19:50",

        "MY-HOST": 35

    }

] 

 

 

 

 

 

Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

We only check the first object in the collection, you will have to "preprocess" the data before you pass it to jChartFX, if you do not find the Avg, Completed or Aborted properties you will want to add those properties to the first object and use cfx.Chart.Hidden as the value.

A value of hidden is what we also assume when a property is missing.

JuanC 

Link to post
Share on other sites
  • 0

Hi,

With some help from a Groovy forum I found a way to fill in "missing" values with default values through out the json before passing it to jChartFX.

The default value I am using is 0, but assuming that the missing values are 0 is actually wrong, it would be better to not show the missing values at all. 

Is there a value that can be used for filling in missing values so that the series will still be rendered but the missing values not?


 

Thanks! 

 

Link to post
Share on other sites
  • 0

You should use cfx.Chart.Hidden as your default value.

This value is interpreted as a hidden value, in the case of bar charts, bars with a value hidden are not drawn, in the case of connected galleries such as line, curve, area, a hidden value in the middle of a series will cause the line/curve/area to be broken in two (or more) segments.

JuanC 

Link to post
Share on other sites
  • 0

Hi JuanC,

don't know if this is correct, the series AVG,COMPLETED and ABORTED are not visible at all in the charts

 

SAMPLE JSON

 [

    {

        "Date": "2013-11-14 09:53",

        "AVG": "cfx.Chart.Hidden",

        "COMPLETED": "cfx.Chart.Hidden",

        "ABORTED": "cfx.Chart.Hidden",

        "MY-VAIO": 28

    },

    {

        "Date": "2013-11-14 09:54",

        "AVG": 5606,

        "COMPLETED": 2,

        "ABORTED": 0,

        "MY-VAIO": 67

    },

    {

        "Date": "2013-11-14 09:55",

        "AVG": "cfx.Chart.Hidden",

        "COMPLETED": "cfx.Chart.Hidden",

        "ABORTED": "cfx.Chart.Hidden",

        "MY-VAIO": 71

    },

    {

        "Date": "2013-11-14 09:56",

        "AVG": 5130,

        "COMPLETED": 2,

        "ABORTED": 0,

        "MY-VAIO": 74

    }

] 

 

 

 

Is this how the sample JSON above should look like to render the missing series?

 

 [

    {

        "Date": "2013-11-14 09:53",

        "AVG": "0",

        "COMPLETED": "0",

        "ABORTED": "0",

        "MY-VAIO": 28

    },

    {

        "Date": "2013-11-14 09:54",

        "AVG": 5606,

        "COMPLETED": 2,

        "ABORTED": 0,

        "MY-VAIO": 67

    },

    {

        "Date": "2013-11-14 09:55",

        "AVG": "cfx.Chart.Hidden",

        "COMPLETED": "cfx.Chart.Hidden",

        "ABORTED": "cfx.Chart.Hidden",

        "MY-VAIO": 71

    },

    {

        "Date": "2013-11-14 09:56",

        "AVG": 5130,

        "COMPLETED": 2,

        "ABORTED": 0,

        "MY-VAIO": 74

    }

]  

 

 

Thanks! 

Link to post
Share on other sites
  • 0

One more obeservation,

 it appears that if the value cfx.Chart.Hidden is present anywhere in the series with this gallery type cfx.Gallery.Curve, then there will only be dots rendered with no curved line between them in the serie.

Also dont know how to handle this.

Thanks! 

 

Link to post
Share on other sites
  • 0

cfx.Chart.Hidden is not a string it is a value that you must use as a number, e.g. assume you have an incomplete json similar to your original post

var items = [{"Date": "2013-11-12 19:45", "MY-HOST": 66}, {"Date": "2013-11-12 19:46", "MY-HOST": 48},{"Date": "2013-11-12 19:47", "AVG": 50, "COMPLETED": 1, "ABORTED": 0, "MY-HOST": 36},{"Date": "2013-11-12 19:48", "AVG": 40, "COMPLETED": 2, "ABORTED": 0, "MY-HOST": 28},{"Date": "2013-11-12 19:49","AVG": 25, "COMPLETED": 1, "ABORTED": 0, "MY-HOST": 31}, {"Date": "2013-11-12 19:50", "MY-HOST": 35}]; 

If you know the fields that you expect in your json you could code it like this

var obj = items[0];

if (obj["MY-HOST"] === undefined)

    obj["MY-HOST"] = cfx.Chart.Hidden;

if (obj["AVG"] === undefined)

    obj["AVG"] = cfx.Chart.Hidden;

if (obj["COMPLETED"] === undefined)

    obj["COMPLETED"] = cfx.Chart.Hidden;

if (obj["ABORTED"] === undefined)

    obj["ABORTED"] = cfx.Chart.Hidden;

If you don't know the fields you might have to write a more complex code that iterates through all the objects, finds out all numeric properties and then add the missing properties to the first object of the collection.

Hope this helps.

JuanC 

Link to post
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...