How to combine two line graphs into one graph using jfreechart? - jfreechart

I am using a jfreechart to show a line graph. I want to use same graph to show another line graph. Can anyone tell me how to do that?
Thanks in advance

JFreeChart chart = ... //Get the chart with your first dataset.
CategoryPlot plot = chart.getCategoryPlot();
plot.setDataset(1, anotherDataset); //The '1' at the first parameter is
//the index of dataset.
//Thus, '1' for the second dataset.
... //some other settings to the plot, with index=1.
plot.setRenderer(1, someRenderer);
Then we can get the graph with this chart.

Related

Connecting datapoints seperated by empty points in a win form chart

I have two series to be plotted as a line chart with Win Form Charts. The first series has x,y values of
{(datetime1:4),(datetime2:4),(datetime3:4),(datetime4:1),(datetime5:3)}
And the second series has x,y values of
{(datetime1:4),(datetime3:14),(datetime5:6)}
Since the second series has datetime2 and datetime4 missing, I have added DbNull.Value as value for these points. So now the second series will be
{(datetime1:4),(datetime2:DbNull.Value),(datetime3:14),(datetime4:DbNull.Value),(datetime5:6)}
Because of this the second series shows only dots. Could you please suggest me how can I connect these empty points with the average of the two closest data points.
The way to acheive this is
mySeries.EmptyPointStyle.BorderDashStyle = ChartDashStyle.Dash; // select the style you want
mySeries.EmptyPointStyle.Color = Color.Gray; // setting the color might be required
mySeries["EmptyPointValue"] = "Average";

How to create multiple vertical lines jfreechart

I want to create verical lines , the thing is , for example i have a space between x=0 and x=20 , and i have a jtextfield where the user can digit a number , and that number will create the same number of vertical lines in that space of x=0 and x=20. i'm using xyplot , and the problem is , if i use the same series to add the points i will get a zigzag line , for exemple if i do:
series.add(0,-2)
series.add(0,2)
series.add(4,-2)
series.add(4,2)
So for differents coordenate xx i have to have a different seried . But if i do a different series i have to do a diferente dataset too, because when i try to add different series to the same dataset i get a error. i thought about using a for loop to create differents dataset and differents series , but i have no ideia how can i do that . i could use the grid line to do this , but i only want to see the lines between x=0 and x=20 , and i don't know if i can do that with the grid line , and i don't know how to change the space between grid lines .
So maybe you can tell me so ideias about this , and if you could guide me , that would be great.
There is a facility in JFreeChart to add "markers" to a plot to mark particular values along an axis. The markers are typically drawn as lines across the plot, perpendicular to the x-axis (domain markers) or the y-axis (range markers). In your case, it sounds like you want to add a fixed number of domain markers to the plot, so you should call the addDomainMarker() method on the plot.

JFreeChart - Vertical Line Chart

HI how to create a chart like http://livedocs.adobe.com/flex/3/html/images/VerticalLine.png. Using XYPlot. Thanks in advance.
Many charts let you specify the PlotOrientation in the corresponding chart factory, but createTimeSeriesChart() is not one of them. As an alternative, you can create your own variation using the source as a guide.
Addendum: As #Gavin comments, PlotOrientation.VERTICAL is the default for `XYPlot, so you'd do something like this (untested):
XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
plot.setOrientation(PlotOrientation.HORIZONTAL);

Plotting Distances of Points in JfreeChart

I need help in Plotting the Distance of points on Scatter Plot and My Array consist of values whose distances are needed to be calculated.
A1-(0.3883,0.4197)
A2-(0.3960,0.3836)
A3-(0.4065,0.4032)
The Distance between A1,A2 is 0.0369 and the distance between A1,A3 is 0.0245 and similarly the Distance between A2,A3 is 0.0221.
My question is how to Plot this Distances(0.0369 of(A1,A2),0.0245 of(A1,A3)..) of that paired values on a Scatter Plot(JfreeChart)?. Please give me Some suggestions on how to a approach this Problem.
As your data model is a graph, I'd look at JGraph, which has better support for labeled edges.
In JFreeChart, you could add an item label or tool tip generator to the XYLineAndShapeRenderer. The generator would have to query your data model for the relevant edge value. You could arrange for your data model to implement TableModel and use a JTable as an ancillary display, as shown in CrosshairDemo1 & 2.

Jfreechart DateAxis should show date on the top of first tick unit

can anyone help me how I could display the date alone on top of the first tick unit of DateAxis in Jfreechart Gantt
Like this:
6july|||7july|||8july|||
valueAxis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR,6));
///what needs to be extended here to get the desired format as said above
valueAxis.setDateFormatOverride(new SimpleDateFormat("'|'d,MMM"));
Thank you.
Because a Gantt chart uses a DateAxis for the range, you can invoke setDateFormatOverride(), as shown here. Of course you'll want to use getRangeAxis().
Addendum: Reading more closely, you can use setLowerMargin() and/or setUpperMargin() on the range axis to leave some room for the date over the end ticks.

Resources