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

Message ListMessage List     Post MessagePost Message

  jscript formatting values
Posted by Warren on Apr-10-2018 11:04
Hi,

I think this is a simple question, I hope you can help...

I am having trouble formatting values through jscript samples.

eg
viewer.showTextBox("dataLabel" + i + "_" + j, xCoor + 5, yCoor, JsChartViewer.Left,
                        dataSet.getValue(xIndex).toPrecision(5)/1000, "padding:0px 3px;font:bold 11px Arial;" +
                        "background-color:" + color + ";color:#FFFFFF;-webkit-text-size-adjust:100%;");

Can you give me some examples of how to format the xIndex value for numbers or dates. In my example, the value is a large number eg 9375669.52 and I would like to format to 9,375K . In other examples, I used something like "${={value}/1000|0}K", however I can't get this to work in jscript.

cheers
Warren

  Re: jscript formatting values
Posted by Peter Kwan on Apr-11-2018 00:54
Hi Warren,

You can format the number using Javascript or using ChartDirector. For Javascript, the code is:

"$" + (dataSet.getValue(xIndex)/1000).toFixed().replace(/(d)(?=(d{3})+(,|$))/g, '$1,') + "K"

With ChartDirector, I found that the formatValue in Javascript only supports simple formatting, and not work like the one on the server side (with format expression support). For your case, you can use:

"$" + c.formatValue(dataSet.getValue(xIndex)/1000, "0,.") + "K"

Hope this can help.

Regards
Peter Kwan