Hello,
I’m currently using DataStore to provide data to 2 components.
One of them is a dhtmlXChart (type : Pie) .
example of data
id name amount
1 FR 1000.00
2 UK 1200.00
…
50 NZ 250.00
my chart is very ugly as there are to many rows…
Could you please tell me how I can filter the datastore (or dataset) so that I can get only :
_ the rows where the amount is bigger a specified value
OR
_ the 5 rows with the biggest value
Thanks for you advices.
Regards
You can use sync for the chart like next
barChart1.sync(data, function(){
this.silent(function(){
this.filter(function(obj){
return obj.value > 5;
});
});
});
Second parameter will be applied after each data syncing, you can place here code to alter dataset after syncing.
Hi Stanislav and thanks for your help ![:slight_smile: :slight_smile:](//forum.dhtmlx.com/images/emoji/twitter/slight_smile.png?v=5)
This doesn’t work for me.
Here is my js code :
// init datastore
var statGlobal = new dhtmlXDataStore({
url:"data.php?action=getds1&tdate=2&period=m1",
datatype: "xml"
});
// ReSync Grid
stats_grid.sync(statGlobal);
// Resync Chart
stats_chart.sync(statGlobal, function(){
this.silent(function(){
this.filter(function(obj){
return obj.value > 5;
});
});
});
Here is a sample of my Data (xml):
<data>
<item id="000">
<label>CAT01</label>
<total>16.71</total>
</item>
<item id="001">
<label>CAT02</label>
<total>112.84</total>
</item>
<item id="002">
<label>CAT03</label>
<total>409.76</total>
</item>
<item id="003">
<label>CAT04</label>
<total>371.24</total>
</item>
<item id="005">
<label>CAT05</label>
<total>3.34</total>
</item>
<item id="006">
<label>CAT06</label>
<total>261.87</total>
</item>
<item id="007">
<label>CAT07</label>
<total>677.56</total>
</item>
<item id="008">
<label>CAT08</label>
<total>203.11</total>
</item>
<item id="009">
<label>CAT09</label>
<total>445.30</total>
</item>
<item id="010">
<label>CAT10</label>
<total>52.20</total>
</item>
<item id="012">
<label>CAT12</label>
<total>5.57</total>
</item>
<item id="013">
<label>CAT13</label>
<total>7.10</total>
</item>
</data>
While using the function you gave me, the chart disappears.
Regards
Ok soorry, I 've just found my mistake.
replaced
return obj.value > 5;
by
return obj.total> 3000; // for example
However, I need to find how I can sort my Dataset by total DESC and then take the 5 ones with biggest total value…
Regards
Replace filter call this something like next
chart.sort("total","asc","int");
//filter out 5 top records
var value = 0;
this.filter(function(obj){
if (value > 4) return false;
value ++;
return true;
});
First command will sort data, code after that will filter out 5 top records.
It will display < OK > and < Cancel > two button.
I want to ask how to operate these two button that add function and action to them ?