R
Robert M. Gary
I'm using JFreeChart and would like to have both a line on a graph and
several points. I started out using ChartFactory.createXYLineChart
which showed the lines well but the points only appeared in the legends
(perhaps they were too small to be visible on the graph). So I switched
to ChartFactory.createScatterPlot which shows the points wonderfully
but now my line is not continuous.
Is there a way to put both lines and well seen points on the same
graph? I was surprised that when adding points to a graph you cannot
select attribtues such as color, size, etc of the points.
Here is abriviated what I am doing...
....
//=====>>>THIS IS A LINE<<=======
XYSeries series = new XYSeries("EF");
for (int i = 0; i < collection.numreturnstograph; i++)
{
series.add(collection.returns, collection.stddevs);
}
//===>>>THIS IS A POINT<<<===
XYSeries seriesMVP = new XYSeries("MVP");
seriesMVP.add(collection.MVPreturn,
Math.sqrt(collection.MVPvariance));
// org.jfree.chart.plot.ColorPalette foo = new ColorPalette();
XYSeriesCollection xyDataset = new XYSeriesCollection(seriesMVP);
//===>>>THIS IS A POINT<<<===
if (collection.Custreturn != 0)
{
XYSeries custseries = new XYSeries("Current");
custseries.add(collection.Custreturn, collection.Custvariance);
xyDataset.addSeries(custseries);
}
//===>>>THIS IS A POINT<<<===
if ( collection.Rp != 0 )
{
XYSeries reqseries = new XYSeries("RequestReturn");
reqseries.add(collection.requestedReturn,
collection.requestedStdDev);
xyDataset.addSeries(reqseries);
}
//add the actual EF line last so it is
behind the points when overlapping
xyDataset.addSeries(series);
// JFreeChart chart = ChartFactory.createXYLineChart(
JFreeChart chart = ChartFactory.createScatterPlot(
"Portfolio's Efficient Frontier", // Title
"Monthly Return", // X-Axis label
"Risk StdDev", // Y-Axis label
xyDataset, // Dataset
PlotOrientation.HORIZONTAL, true, // Show legend
false, false);
....
Thanks!
several points. I started out using ChartFactory.createXYLineChart
which showed the lines well but the points only appeared in the legends
(perhaps they were too small to be visible on the graph). So I switched
to ChartFactory.createScatterPlot which shows the points wonderfully
but now my line is not continuous.
Is there a way to put both lines and well seen points on the same
graph? I was surprised that when adding points to a graph you cannot
select attribtues such as color, size, etc of the points.
Here is abriviated what I am doing...
....
//=====>>>THIS IS A LINE<<=======
XYSeries series = new XYSeries("EF");
for (int i = 0; i < collection.numreturnstograph; i++)
{
series.add(collection.returns, collection.stddevs);
}
//===>>>THIS IS A POINT<<<===
XYSeries seriesMVP = new XYSeries("MVP");
seriesMVP.add(collection.MVPreturn,
Math.sqrt(collection.MVPvariance));
// org.jfree.chart.plot.ColorPalette foo = new ColorPalette();
XYSeriesCollection xyDataset = new XYSeriesCollection(seriesMVP);
//===>>>THIS IS A POINT<<<===
if (collection.Custreturn != 0)
{
XYSeries custseries = new XYSeries("Current");
custseries.add(collection.Custreturn, collection.Custvariance);
xyDataset.addSeries(custseries);
}
//===>>>THIS IS A POINT<<<===
if ( collection.Rp != 0 )
{
XYSeries reqseries = new XYSeries("RequestReturn");
reqseries.add(collection.requestedReturn,
collection.requestedStdDev);
xyDataset.addSeries(reqseries);
}
//add the actual EF line last so it is
behind the points when overlapping
xyDataset.addSeries(series);
// JFreeChart chart = ChartFactory.createXYLineChart(
JFreeChart chart = ChartFactory.createScatterPlot(
"Portfolio's Efficient Frontier", // Title
"Monthly Return", // X-Axis label
"Risk StdDev", // Y-Axis label
xyDataset, // Dataset
PlotOrientation.HORIZONTAL, true, // Show legend
false, false);
....
Thanks!