Jump to content
JChartFX Community
  • 0
Sign in to follow this  
ql_maxg

Set no format for x-axis labels

Question

Hello

I need to pass some labels for x axis in following format '2015-02-02', other words in date format. But, I don't want jchartfx to identify it as date and convert to date label in culture format. I want it to be treated as some custom text labels and preserve the order of data. Is it possible to do?

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

We try to use dates or strings using ISO 8601 format as dates, e.g. the following data will create a chart where we identify the field Date as holding dates, notice that we used lines as this gallery supports XY data so it is easier to see that the distance between the first 2 points is not the same as the last 2 points.

 

chart1.setDataSource([{"Value":12, "Date":"2016-02-15"}, {"Value":14, "Date":"2016-02-16"}, {"Value":11, "Date":"2016-02-18"}]);

chart1.setGallery(cfx.Gallery.Lines);
 
To workaround this you need to specify how each field will be used, e.g.
 
var fields = chart1.getDataSourceSettings().getFields();
var field;
field = new cfx.FieldMap();
field.setName("Value");
field.setUsage(cfx.FieldUsage.Value);
fields.add(field);
 
field = new cfx.FieldMap();
field.setName("Date");
field.setUsage(cfx.FieldUsage.Label);
fields.add(field);
 
Note that you have to assign the fields before using setDataSource, you will notice that the points in the line are equally spaced but there is a bug that will still format the dates on the user's culture. This will be fixed in our next build.
 
A workaround before this issue is fixed would be to add a character (e.g. a whitespace) in the first element's date to trick our detection code.
 
JuanC

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×