I have the following LineChart in my FXML file:
<LineChart fx:id="line_chart">
<xAxis><CategoryAxis label="Time" /></xAxis>
<yAxis><NumberAxis label="Price" /></yAxis>
</LineChart>
In my controller file, I populate my series like the following code:
XYChart.Series<String,Number> series = new XYChart.Series<>();
DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
for(int i = 0; i < lineChart_DATA.size(); i++)
series.getData().add(new XYChart.Data(df.format(lineChart_DATA.get(i).date),
lineChart_DATA.get(i).balance));
series.setName(GUISet.type);
line_chart.getData().add(series);
line_chart.setTitle("Title");
When I run my program, the X-axis only displays the last string value. I noticed that by running a second time the same code, the X-axis displays correctly.
Did I miss something in my code ?
I dont know if it is a specific bug or maybe I did not use LineChart properly but by disabling the animation of the LineChart, I was able to solve my issue.
line_chart.setAnimated(false);
Related
I'm working with jfreechart-fx. I created a scroll panel and I have a ChartViewer (not a ChartPanel) inside of it. Inside the chart, I plot data using a CombinedDomainXYPlot. I add some data to the combined plot at runtime:
XYPlot subplot;
for (int i=0; i<10; i++){
dataset = .....
subplot = new XYPlot(dataset, null, rangeAxis1, renderer);
myCombinedPlot.add(subplot)
}
String panel_title = "bla bla";
myChartViewer.setChart(new JFreeChart(panel_title, JFreeChart.DEFAULT_TITLE_FONT, myCombinedPlot, false));
Now, when I drag and drop on my graph, I see that the default operation of mouse is the zoom on the signal. How do I disable this default function? I tried the following, but it doesn't work:
myChartViewer.getCanvas().setRangeZoomable(false);
myChartViewer.getCanvas().setDomainZoomable(false);
This behavior is controlled by an instance of ZoomHandlerFX installed by the ChartViewer constructor. To eliminate zooming entirely, simply remove the handler.
ChartViewer chartViewer = new ChartViewer(chart);
ChartCanvas canvas = chartViewer.getCanvas();
canvas.removeMouseHandler(canvas.getMouseHandler("zoom"));
If you later need to restore the handler, invoke addMouseHandler() like this:
canvas.addMouseHandler(new ZoomHandlerFX("zoom", chartViewer));
I am trying to design progressive doughnut chart. I have a problem like I am getting doughnut chart but not progressive.
Is it possible to design progressive doughnut chart using achartengine? If it is possible how to do? please anyone can help?
DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setApplyBackgroundColor(true);
renderer.setShowLegend(false);
renderer.setScale((float)1.3);
renderer.setShowLabels(false);
renderer.setStartAngle(270);
//renderer.setBackgroundColor(Color.rgb(222, 222, 200));
renderer.setLabelsColor(Color.BLUE);
return ChartFactory.getDoughnutChartView(MainActivity.this,
buildMultipleCategoryDataset("Project budget", titles1, values),
renderer);
}
private MultipleCategorySeries buildMultipleCategoryDataset(String title,
List<String[]> titles1, List<Float> values) {
// TODO Auto-generated method stub
MultipleCategorySeries series = new MultipleCategorySeries(title);
int k = 0;
for (Float value : values) {
series.add(title, titles1.get(k), values);
k++;
I used this chart in one of my application which requires real time battery value tracking and showing using doughnut chart. so, i created an example project for this.
Demo Doughnut Chart
just download/import this example to your workspace and run.
I am developing a JaxaFX application that generates reports by taking data from a MySQL database. I came across an issue when working with piecharts. Whenever the fetched data is 0, the label getting displayed for it overlaps with the other labels in the piechart making it difficult to read.
Relevant bits of Code:
Fetching the Data:
Get_data_from_pos_basket_for_reporting getreportPaymentPaidUnpaidNoClass=new Get_data_from_pos_basket_for_reporting();
getreportPaymentPaidUnpaidNoClass.getreportPaymentPaidUnpaidNo(fromDate, untilDate);
double amountPaid,amountUnpaid;
int totalPaid,totalUnpaid;
amountPaid=getreportPaymentPaidUnpaidNoClass.getAmountPaid();
amountUnpaid= getreportPaymentPaidUnpaidNoClass.getAmountUnpaid();
totalPaid=getreportPaymentPaidUnpaidNoClass.getTotalPaid();
totalUnpaid=getreportPaymentPaidUnpaidNoClass.getTotalUnpaid();
double totalamountPaidUnpaid=amountPaid+paymentSystem+amountUnpaid;
double totalNoPaidUnpaid=totalPaid+totalUnpaid;
// DecimalFormat df = new DecimalFormat("0.00");
double percentagePaidAmount=((amountPaid/totalamountPaidUnpaid)*100);
double percentageUnpaidAmount=((amountUnpaid/totalamountPaidUnpaid)*100);
double percentagePaidTotal=((totalPaid/totalNoPaidUnpaid)*100);
double percentageUnpaidTotal=((totalUnpaid/totalNoPaidUnpaid)*100);
Setting the Piechart:
ObservableList<PieChart.Data> pieChartData3 =
FXCollections.observableArrayList(
new PieChart.Data("Paid\n"+(df.format(percentagePaidAmount))+"%", amountPaid),
new PieChart.Data("Unpaid\n"+(df.format(percentageUnpaidAmount))+"%", amountUnpaid));
PieChart chart3 = new PieChart(pieChartData3);
chart3.getStyleClass().add("chart-legend");
chart3.setTitle("Payment Details[Total Amount]");
VBox vBoxPie3= new VBox();
vBoxPie3.getChildren().addAll(chart3);
Please suggest a solution such that the labels don't overlap with each other.
I'm currently developing an android app for reading out multiple sensor values via Bluetooth and display them in a graph. When I stumbled upon jjoe64's GraphViewLibrary, I knew this would fit my purposes perfectly. But now I'm kind of stuck. Basically, I wrote a little function that would generate and display the values of three sensors in 3 different graphs one under the other. This works just fine when the activity is started first, all three graphs a nicely rendered and displayed. But when I want to update the graphs with different values using the resetData()-method to render the new values in each graph, only the last of the three graphs is updated. Obviously, because it's the last graph generated using this rather simple function. My question is: Is there any other elegant way to use a function like mine for generating and updating all three graphs one after the other? I already tried to set the GraphView variable back to null and different combinations of removing and adding the view. Passing the function a individual GraphView-variable like graphView1, graphView2... does also not work.
Here is the function:
private GraphView graphView;
private GraphViewSeries graphViewSerie;
private Boolean graphExisting = false;
...
public void makeGraphs (float[] valueArray, String heading, int graphId) {
String graphNumber = "graph"+graphId;
int resId = getResources().getIdentifier(graphNumber,"id", getPackageName());
LinearLayout layout = (LinearLayout) findViewById(resId);
int numElements = valueArray.length;
GraphViewData[] data = new GraphViewData[numElements];
for (int c = 0; c<numElements; c++) {
data[c] = new GraphViewData(c+1, valueArray[c]);
Log.i(tag, "GraphView Graph"+graphId+": ["+(c+1)+"] ["+valueArray[c]+"].");
}
if (!graphExisting) {
// init temperature series data
graphView = new LineGraphView(
this // context
, heading // heading
);
graphViewSerie = new GraphViewSeries(data);
graphView.addSeries(graphViewSerie);
((LineGraphView) graphView).setDrawBackground(true);
graphView.getGraphViewStyle().setNumHorizontalLabels(numElements);
graphView.getGraphViewStyle().setNumVerticalLabels(5);
graphView.getGraphViewStyle().setTextSize(10);
layout.addView(graphView);
}
else {
//graphViewSerie = new GraphViewSeries(data);
//graphViewSerie.resetData(data);
graphViewSerie.resetData(new GraphViewData[] {
new GraphViewData(1, 1.2f)
, new GraphViewData(2, 1.4f)
, new GraphViewData(2.5, 1.5f) // another frequency
, new GraphViewData(3, 1.7f)
, new GraphViewData(4, 1.3f)
, new GraphViewData(5, 1.0f)
});
}
And this is the function-call depending on an previously generated array (which is being monitored to be filled with the right values):
makeGraphs(graphData[0], "TempHistory", 1);
makeGraphs(graphData[1], "AirHistory", 2);
makeGraphs(graphData[2], "SensHistory", 3);
graphExisting = true;
Any help and / or any feedback in general is greatly appreciated! Lots of thanks in advance!
EDIT / UPDATE:
Thanks to jjoe64's answer I was able to modify the function to work properly. I was clearly having a mistake in my thinking, since I thought I'd also be changing a GraphViewSeries-object I would handle my function as additional parameter (which I tried before). Of course this does not work. However, with this minor Improvements I managed to make this work using a Graphviewseries Array. To give people struggling with a similar problem an idea of what I had to change, here the quick-and-dirty draft of the solution.
I just changed
private GraphViewSeries graphViewSerie;
to
private GraphViewSeries graphViewSerie[] = new GraphViewSeries[3];
and access the right Series using the already given parameter graphId within the function (if-clause) like this:
int graphIndex = graphId - 1;
graphViewSerie[graphIndex] = new GraphViewSeries(data);
In the else-clause I'm updating the series likewise by calling
graphViewSerie[graphIndex].resetData(data);
So, once again many thanks for your support, jjoe64. I'm sorry I wasn't able to update the question earlier, but I did not find time for it.
of course it is not working correct, because you save always the latest graphseries-object in the member graphViewSerie.
First you have to store the 3 different graphviewseries (maybe via array or map) and then you have to access the correct graphviewseries-object in the else clause.
I am creating a chart using mxml. The mxml tags only create a chart with a horizontal axis and vertical axis.
My result event handler has actionscript code that loops through the xml result set and creates all the series (line series and stacked bar). This part of the code works fine.
Now I need to use the functionfill function to set individual colors to each series. All the examples I have found call the functionfill from within an MXML tag, like so:
<mx:ColumnSeries id="salesGoalSeries"
xField="Name"
yField="SalesGoal"
fillFunction="myFillFunction"
displayName="Sales Goal">
I am having trouble calling functionfill from actionscript.
A portion of the code that build the data series is below:
if (node.attribute("ConfidenceStatus")=="Backlog"
|| node.attribute("ConfidenceStatus")=="Billings") {
// Create the new column series and set its properties.
var localSeries:ColumnSeries = new ColumnSeries();
localSeries.dataProvider = dataArray;
localSeries.yField = node.attribute("ConfidenceStatus");
localSeries.xField = "TimebyDay";
localSeries.displayName = node.attribute("ConfidenceStatus");
localSeries.setStyle("showDataEffect", ChangeEffect);
localSeries.fillFunction(setSeriesColor(xxx));
// Back up the current series on the chart.
var currentSeries:Array = chart.series;
// Add the new series to the current Array of series.
currentSeries.push(localSeries);
//Add Array of series to columnset
colSet.series.push(localSeries);
//assign columnset to chart
chart.series = [colSet];
My setSeriesColor function is:
private function setSeriesColor(element:ChartItem, index:Number):IFill {
var c:SolidColor = new SolidColor(0x00CC00);
var item:ColumnSeriesItem = ColumnSeriesItem(element);
//will put in logic here
return c;
}
What parameters do I put in the line localSeries.fillFunction(setSeriesColor(xxx)) ?
I tried localSeries as the first argument but I get an implicit coercion error telling me localSeries can't be cast as ChartItem.
How do I call the function correctly?
localSeries.fillFunction = setSeriesColor;
The code you have right now is actually CALLING setSeriesColor the way you have it set up. You only want it to refer to a reference of the function, not calling it, so just send it "setSeriesColor" as a variable.