ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Pie chart label containing formatted date and respective data value
Posted by sofie smith on Sep-05-2014 17:32
Hi

I am trying to render a pie chart label in Java as below.

chart.setLabelFormat("{value|yy-nn-dd hh:nn}"
          + "\\n" + "{value}%");
chart.setData(dataValues, labels);

My problem is pie chart always has the date displayed as  01-00-01 00:00.

However the "\\n" + "{value}%" is represented correctly.

Please note that the labels array contains the correct time in milliseconds represented as
String values.


How do I get my chart to represent the dates correctly?.

Thank you
Sofie

  Re: Pie chart label containing formatted date and respective data value
Posted by Peter Kwan on Sep-06-2014 02:48
Hi sofie,

The {value} refers to the data value, and the {label} refers the the sector labels. In your
case, "{value|yy-nn-dd hh:nn}" means you are formatting the data value as a date/time,
as opposed to the sector labels. As the data value is small in your case, which means the
date/time is just few seconds after Jan 1, 0001 00:00:00, so the date is displayed as 01-
00-01 00:00. (By the way, yy-nn-dd should be yy-mm-dd. If you use yy-mm-dd, it should
display as 01-01-01 for Jan 1, 0001.)

The {label} represents labels, but as you have mentioned in your message, the labels are
text strings, not numbers as according to your programming langauge. Text strings cannot
be formatted, as they are not numbers or date/time as according to your programming
langauge.

If you would like the labels to be date/time, please format them before you pass then to
ChartDirector. For example:

//parse the text string into a number, then format it, and store the result back to the array
for (int i = 0; i < labels.Length; ++i)
   labels[i] = c.formatValue(Double.Parse(labels[i], "{value|yy-mm-dd hh:nn}"));

Hope this can help.

Regards
Peter Kwan

  Re: Pie chart label containing formatted date and respective data value
Posted by sofie smith on Sep-09-2014 16:24
Thanks for your reply. However formatValue is not giving the correct format

In my labels[] I have timestamp. The timestamp is in milliseconds and I do the following

c.formatValue(Double.parseDouble(labels[i]), "{value|yy-mm-dd hh:nn}");

Please advice.

Thank you

  Re: Pie chart label containing formatted date and respective data value
Posted by Peter Kwan on Sep-09-2014 21:41
Hi sofie,

Sorry for this issue. By "timestamp", I assume you are referring to the date/time as
represented by milliseconds elapsed since 1970-1-1 00:00:00 UTC.

In this case, may be you can try the code:

c.formatValue(Chart.CTime((int)(Long.parseLong(labels[i]) / 1000)), "{value|yy-mm-dd
hh:nn}");

Another method is to use Java code to format the labels[i] into hh:nn before passing the
text string to ChartDirector.

Regards
Peter Kwan