NuiChart( json )

From NWN Lexicon
Jump to navigationJump to search
Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.

Renders a chart.


// Renders a chart.
// Currently, min and max values are determined automatically and
// cannot be influenced.
json                    // Element
NuiChart(
  json jSlots           // NuiChartSlot[]
);


Returns

jons Element

Parameters

jSlots
NuiChartSlot


Description

Renders a chart.


Remarks


Known Bugs

Not a bug, but there appears to be a hard limit of drawing 4 NuiChartSlots per NuiChart. Adding more than 4 will display the legends for them, but not draw the data for > 4th elements.

NUI code doesn't limit how many slots you can add (hence the legend) during definition, only during the draw process. The legend drawing is handled separately from the chart drawing, which creates the mismatch. -Jasperre

Version

This function was added in 1.85.8193.31 of NWN:EE.


Example

void main()
{
	object oPC = GetFirstPC();

	// This is your data to plot.
	json jData = JsonArray();
	jData	   = JsonArrayInsert(jData, JsonFloat(10.0));
	jData	   = JsonArrayInsert(jData, JsonFloat(90.0));
	jData	   = JsonArrayInsert(jData, JsonFloat(30.0));
	jData	   = JsonArrayInsert(jData, JsonFloat(130.0));


	// each data is a slot (ie, line or column).  You have have multiple slots (ie, lines) per chart, but in this example, just one
	// We are binding with NuiBind("jdata"), but could also add direct with just `jData`, see note at end.
    // We're using NUI_CHART_TYPE_LINES in this example, but could also have columns instead with NUI_CHART_TYPE_COLUMN
	json jSlot = NuiChartSlot(NUI_CHART_TYPE_LINES, JsonString("This is our legend inline"), NuiColor(255, 255, 255, 255), NuiBind("jdata"));


	// Add the slot (ie, line) to array and then add that entire array of slots to the chart
	// Even if you only have one slot, still needs to be in an array I think.
	json jSlots = JsonArray();
	jSlots		= JsonArrayInsert(jSlots, jSlot);

	json jChart = NuiChart(jSlots);

	// This is just generic boilerplate code to get our chart to display

	json jColList = JsonArray();
	jColList	  = JsonArrayInsert(jColList, jChart);
	json jLayout  = NuiCol(jColList);

	json jWindow = NuiWindow(jLayout, JsonString("test"), NuiRect(-1.0, -1.0, 400.0, 300.0), JsonBool(TRUE), JsonBool(FALSE), JsonBool(TRUE), JsonBool(FALSE), JsonBool(TRUE));


	int nToken = NuiCreate(oPC, jWindow, "chart");

	// We generally want to bind it, so we can update the chart as data changes.  But could also add it direct instead, if you know it won't change.
	NuiSetBind(oPC, nToken, "jdata", jData);
}

See Also

functions:

NUI Functions NuiChartSlot