|
Unit (M K m μ n) notation of barchart data |
Posted by Jungruyl on Apr-23-2025 10:29 |
|
I want to display a very small value on a barchart.
It usually ranges from 1.0e-3 to 1.0e-7,
and currently it is output in {value|e4} format, but in other parts besides the chart,
it is displayed using units such as m(1000000), k(1000), m(1/1000), u(1/1000000), n(1/1000 000 00). 0.3u, 0.12m, etc. (
Current usage - layer.setDataLabelFormat("{dataSetName}:{value|e4}"); )
I would like to ask if there is a format function that displays units like the above when displaying data on a charbar.
Thank you.
|
Re: Unit (M K m μ n) notation of barchart data |
Posted by Peter Kwan on Apr-26-2025 18:17 |
|
Hi Jungruyl,
Sorry for the late reply.
If you always want to use a specific unit (like m), you can use:
layer.setDataLabelFormat("{dataSetName}:{value*1000|e4}m");
The above will display the value * 1000, and then add the letter "m". So 0.001234 will be displayed as 1.234m.
If you want every value to be displayed different based on its data value, you can use custom formatting. It is like:
// Add the bar layer
BarLayer layer = c.addBarLayer2(Chart.Side, 30);
layer.addDataSet(data0, 0xff8080, "AAA");
layer.addDataSet(data1, 0x80ff80, "BBB");
// Always show label
layer.setMinLabelSize(0);
for (int i = 0; i < layer.getDataSetCount(); ++i)
{
DataSet d = layer.getDataSet(i);
for (int j = 0; j < data0.Length; ++j)
{
double dataValue = d.getValue(j);
string label = "";
// Format label according to its value
if (dataValue < 0.001)
label = c.formatValue(dataValue * 1000000, "P4") + "u";
else if (dataValue < 1)
label = c.formatValue(dataValue * 1000, "P4") + "m";
else if (dataValue < 1000)
label = c.formatValue(dataValue, "P4");
else if (dataValue < 1000000)
label = c.formatValue(dataValue/1000, "P4") + "K";
else
label = c.formatValue(dataValue/1000000, "P4") + "M";
layer.addCustomDataLabel(i, j, d.getDataName() + ":" + label).setAlignment(Chart.Left);
}
}
Best Regards
Peter Kwan |
|