Text of grid combo in Chart

Hello,

I’m trying to create a chart out of grid.
I want to connect the label of the chart the first column of my grid. This is a combo.
Therefor I used the following code:

barChart = dhxWins.window("w1").attachChart({ view: "pie", value: "#costs#", label: "#regtype#", group: { by: "#data0#", map: { costs: ["#data7#", "sum"], regtype: ["#data0#"] } },

In this case the chart displays the label as the value of the combo (in our case the ID), but I want to display the combo text in the chart. Is there a possibility for this?

Best regards
Remy

Hello Remy,

Which column type are you using: “co” or “combo” ?

Hi Alexandra

I’m using the column type ‘combo’

Best regards
Remy

In this case, you will need to use dhtmlxCombo API to get an option label by value. And getColumnCombo(columnIndex) returns combo object. So, the “regtype” template in “map” can be like so:

barChart = dhxWins.window("w1").attachChart({ view: "pie", value: "#costs#", label: "#regtype#", group: { by: "#data0#", map: { costs: ["#data7#", "sum"], regtype: [function(obj){ var combo = grid.getColumnCombo(0); var option = combo.getOption(obj.data0); return (option?option.text:obj.data0); }] } },

Hi Alexandra

That function still returns the ID instead of the combo text.

pieChart = dhxWins.window("w1").attachChart({ view: "pie", value: "#income#", label: "#regtype#", group: { by: "#data0#", map: { income: ["#data15#", "sum"], regtype: [function(obj){ var combo = tree.getColumnCombo(0); var option = combo.getOption(obj.data0); alert(option?option.text:obj.data0); return (option?option.text:obj.data0) }] } },

Hi,

please open a ticket in Members’ Support and provide the working demo that allows to recreate the issue locally.

Hi Alexandra

Our members support is expired, otherwise I’d asked this question over there.

Is this code working at your side?
Or did you not test it?

Remy,

getOption(value) is Combo method that returns an option object by its value if an option with such a value exists. Locally this approach works.

You may attach a working demo (wihout including libs of pro edition) - we will check it.

It’s much work to create a demo.

The option returns ''null" in this case:

var combo = tree.getColumnCombo(0); var option = combo.getOption(obj.data0); alert("OPTION: " + option);

When I print out combo, I get “Object object”.

If combo options are loaded async (loadXML or source attribute in “combo” column), the grid and chart will be initialized before combo options are loaded. Therefore, combo.getOption(obj.data0) may return null.

You may try to use something like so if grid columns are configured in xml:

tree.loadXML(url,function(){ var combo = tree.getColumnCombo(0); combo.attachEvent("onXLE",function(){ pieChart.clearAll(); pieChart.parse(tree,"dhtmlxgrid"); }) });

In this case chart data will set after combo is loaded.

Hi Alexandra,

The chart is created after a click on the chart button in a toolbar.
So in that case the combo must be finished loading. I tried your approach with a alert, but the alert is never called.

Best regards

Hi,

we need the complete demo (without libs) to recreate the problem locally. If the combo is loaded before chart init, the method works fine (we tested this approach)