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

Message ListMessage List     Post MessagePost Message

  How to show the actual value of Volume on chart not the 0.88M like?
Posted by Manisha on Aug-04-2015 15:32
Attachments:
Hi Sir,

Thank you so much for helping me out every time, one more issue i am facing is to
show the actual value of Volume indicator on chart like 85.00 not 0.085k is there any
way to do so? my data base save the actual value but the java script code converts it to
let say 0.085M or k.
This value comes from this code

for (var j = 0; j < c.getLayerCount() ; ++j) {
                    var layer = c.getLayerByZ(j);
                    var xIndex = layer.getXIndexOf(xValue);
                    var dataSetCount = layer.getDataSetCount();

                    // In a FinanceChart, only layers showing OHLC data can have 4 data sets
                    if (dataSetCount == 4) {
                        var highValue = layer.getDataSet(0).getValue(xIndex);
                        var lowValue = layer.getDataSet(1).getValue(xIndex);
                        var openValue = layer.getDataSet(2).getValue(xIndex);
                        var closeValue = layer.getDataSet(3).getValue(xIndex);

                        if (closeValue == null)
                            continue;

                        // Build the OHLC legend
                        ohlcLegend =
                            "Open: " + openValue.toFixed(2)+ ", High: " +
highValue.toFixed(2) +
                            ", Low: " + lowValue.toFixed(2) + ", Close: " +
closeValue.toFixed(2);

                        // We also draw an upward or downward triangle for up and down
days and the % change
                        var lastCloseValue = layer.getDataSet(3).getValue(xIndex - 1);
                        if (lastCloseValue != null) {
                            var change = closeValue - lastCloseValue;
                            var percent = change * 100 / closeValue;
                            if (change >= 0)
                                ohlcLegend += "??<span
style='color:#008800;'>▲ ";
                            else
                                ohlcLegend += "??<span
style='color:#CC0000;'>▼ ";
                            ohlcLegend += change.toPrecision(4) + " (" + percent.toFixed(2) +
"%)</span>";
                        }

                        // Add a spacer box, and make sure the line does not wrap within the
legend entry
                        ohlcLegend = "<nobr>" + ohlcLegend + viewer.htmlRect(20, 0) + "
</nobr> ";
                    }
                    else {
                        // Iterate through all the data sets in the layer
                        for (var k = 0; k < dataSetCount; ++k) {
                            var dataSet = layer.getDataSetByZ(k);
                            var name = dataSet.getDataName();
                            var value = dataSet.getValue(xIndex);
                            if ((!name) || (value == null))
                                continue;

                            // In a FinanceChart, the data set name consists of the indicator
name and its latest value. It is
                            // like "Vol: 123M" or "RSI (14): 55.34". As we are generating the
values dynamically, we need to
                            // extract the indictor name out, and also the volume unit (if any).

                            // The unit character, if any, is the last character and must not be a
digit.
                            var unitChar = name.charAt(name.length - 1);
                            if ((unitChar >= '0') && (unitChar <= '9'))
                                unitChar = '';

                            // The indicator name is the part of the name up to the colon
character.
                            var delimiterPosition = name.indexOf(':');
                            if (delimiterPosition != -1)
                                name = name.substring(0, delimiterPosition);

                            // In a FinanceChart, if there are two data sets, it must be
representing a range.
                            if (dataSetCount == 2) {
                                // We show both values in the range
                                //var value2 = layer.getDataSetByZ(1 - k).getValue(xIndex);
                                //name = name + ": " + Math.min(value, value2).toPrecision(4)
+ " - "
                                //    + Math.max(value, value2).toPrecision(4);
                                var value2 = layer.getDataSetByZ(1 - k).getValue(xIndex);
                                name = name + ": " + Math.min(value, value2).toFixed() + " - "
                                    + Math.max(value, value2).toFixed(2);
                            }
                            else {
                                // In a FinanceChart, only the layer for volume bars has 3 data
sets for up/down/flat days
                                if (dataSetCount == 3) {
                                    // The actual volume is the sum of the 3 data sets.
                                    value = layer.getDataSet(0).getValue(xIndex) +
layer.getDataSet(1).getValue(xIndex) +
                                        layer.getDataSet(2).getValue(xIndex);
                                }

                                // Create the legend entry
                                //name = name + ": " + value.toPrecision(4) + unitChar;
                                name = name + ": " + value.toFixed(2) + unitChar;
                            }

Thanks & Regards,
Manisha
VolumeIndicator.png

  Re: How to show the actual value of Volume on chart not the 0.88M like?
Posted by Peter Kwan on Aug-05-2015 02:11
Hi Manisha,

Currently, your code formats the volume using the following line:

name = name + ": " + value.toFixed(2) + unitChar;

You can freely modify the code to format using any method you like. If instead of 0.88M,
you want to show 880K, you can just write the code to format the value the way you want.
For example:
'
if ((unitChar == 'M') and (value < 1)) {
    value *= 1000;
    unitChar = 'K';
}

name = name + ": " + value.toFixed(2) + unitChar;

You can also develop code to handle the unitChar == 'K' or use other method to format the
volume.

Regards
Peter Kwan