Hi,
I would like to change the label of values less than or equal to zeros. Does anyone know how to do this?
Thanks,
Hi,
I would like to change the label of values less than or equal to zeros. Does anyone know how to do this?
Thanks,
Hello @GB1,
What you’re asking is possible but requires some experience with JavaScript code. You’ll have to execute the following steps to achieve what you want:
NOTE: Make sure that your Template contains the Bar Chart element already, which can be inserted by going to: Insert > Business Graphic > Insert Bar Chart.
Open the properties window of the Bar Chart script by double clicking on the icon of the Bar Chart script in the Standard folder in the Scripts pane.
Click on the Expand button.
Scroll down until you see the following JavaScript code at about line 38:
if (!json.theme && !json.colors) {
graph.lineColor = graphs[graphIndex].color;
}
json.graphs.push(graph);
graph.fillColorsField = "fillColor";
…just before the following line of JavaScript code…
json.graphs.push(graph);
…so that the result will become:
if (!json.theme && !json.colors) {
graph.lineColor = graphs[graphIndex].color;
}
graph.fillColorsField = "fillColor";
json.graphs.push(graph);
for (let graphIndex in graphs) {
data[json.graphs[graphIndex].valueField] = table[recordIndex].fields[graphs[graphIndex].field];
}
json.dataProvider.push(data);
// Replace "color" and "green" with the colors you would like to use.
if (parseFloat(data["value-0"]) <= 0) {
data.fillColor = "red";
} else {
data.fillColor = "green";
}
…just after before the following line of JavaScript code:
json.dataProvider.push(data);
…so that it will become:
/**
* The following JavaScript code has been changed at 2023-01-19
* (changed the position of the if-else statement).
*/
for (let graphIndex in graphs) {
data[json.graphs[graphIndex].valueField] = table[recordIndex].fields[graphs[graphIndex].field];
}
// Replace "color" and "green" with the colors you would like to use.
if (parseFloat(data["value-0"]) <= 0) {
data.fillColor = "red";
} else {
data.fillColor = "green";
}
json.dataProvider.push(data);
IMPORTANT:
Hi @Marten
Thanks for the code, it worked perfectly. Using the same method, how do I change the label text of that bar that I changed the color?
Changing the label text can also be done. For this you can execute the following steps:
"labelText"
from "[[value]]"
to something like "[[customValue]]"
so that the result will look something like: "labelText": "[[customValue]]"
.for (let graphIndex in graphs) {
data[json.graphs[graphIndex].valueField] = table[recordIndex].fields[graphs[graphIndex].field];
}
…to something like this…
for (let graphIndex in graphs) {
let customVal = table[recordIndex].fields[graphs[graphIndex].field];
data[json.graphs[graphIndex].valueField] = ((Number(customVal) < 0) ? "0.00" : customVal);
data.customValue = customVal;
}
IMPORTANT: Please note that the NOTE and IMPORTANT notes from my previous comment also apply here.