We are new to using jChartFX so any help would really be appreciated.
We have followed the example for the Bar Chart and have that working fine but when we have tried the Pie Chart we get the correct legends but the Pie chart only plots one item. We have retrieved the data from our database and compared that to how the data looks in the example and it looks to be in the correct format.
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Question
perryworld
Hi,
We are new to using jChartFX so any help would really be appreciated.
We have followed the example for the Bar Chart and have that working fine but when we have tried the Pie Chart we get the correct legends but the Pie chart only plots one item. We have retrieved the data from our database and compared that to how the data looks in the example and it looks to be in the correct format.
This is our code :
<div id="ChartDiv" style="width:600px;height:400px"></div>
<script type="text/javascript" language="javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery.ajax({
type: "POST",
dataType: "json",
url: "/Aircraft/DashboardDataPie.php",
success: function(chartdata)
{
chart1 = new cfx.Chart();
chart1.setDataSource(chartdata);
chart1.setGallery(cfx.Gallery.Pie);
//PopulateBrowserUsage(chart1);
var fields = chart1.getDataSourceSettings().getFields();
var field1 = new cfx.FieldMap();
field1.setName("username");
field1.setUsage(cfx.FieldUsage.RowHeading);
fields.add(field1);
var field2 = new cfx.FieldMap();
field2.setName("userid");
field2.setUsage(cfx.FieldUsage.ColumnHeading);
fields.add(field2);
var fieldVal = new cfx.FieldMap();
fieldVal.setName("sightings");
fieldVal.setUsage(cfx.FieldUsage.Value);
fields.add(fieldVal);
var crosstab = new cfx.data.CrosstabDataProvider();
crosstab.setDataSource(chart1.getDataSource());
chart1.setDataSource(crosstab);
var data = chart1.getData();
data.setSeries(1);
var title = new cfx.TitleDockable();
title.visible = true;
title.setText("My chart Title");
chart1.getTitles().add(title);
var divHolder = document.getElementById('ChartDiv');
chart1.create(divHolder);
}
});
});
And this is the data being returned from our database.
[{ "username" : "Tony15", "userid" : "Tony15", "sightings" : 1506},{ "username" : "richard", "userid" : "richard", "sightings" : 551},{ "username" : "carly", "userid" : "carly", "sightings" : 235},{ "username" : "John", "userid" : "John", "sightings" : 138},{ "username" : "flyhellas", "userid" : "flyhellas", "sightings" : 94},{ "username" : "efc123", "userid" : "efc123", "sightings" : 85}]
Any help would be great, Thanks
Rich
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.