It is the first time I come in this forum. I'm not a graduated software developer, but only an hobbyist keen of Java, Swing and now JFreeChart, and using them in my free time. I'm using JFreeChart 1.0.10 (with NetBeans IDE v.7.3.1) with enthusiam, but I have a question :
I'm designing a chart based on YIntervalChart-Demo1 with the following codes for the dataset
Code: Select all
private static IntervalXYDataset createDataset_Sem(Semaine sem)
{
YIntervalSeries sérieHPl = new YIntervalSeries("H. pleines");
for (short noDeSem = 0 ; noDeSem <= (short) semaines.nbreTotDeSem -1 ; noDeSem++)
{
BigDecimal y_HPl_PMin = semaines.listeSem.get(noDeSem).hPleines_PuissMin;
BigDecimal y_HPl_PMax = semaines.listeSem.get(noDeSem).hPleines_PuissMax;
if (y_HPl_PMin != null && y_HPl_PMax != null)
{
sérieHPl.add(noDeSem, // X
(y_HPl_PMax.doubleValue() - y_HPl_PMin.doubleValue())/2, // Y Any value
y_HPl_PMin.doubleValue(), // Y-low
y_HPl_PMax.doubleValue() // Y-high
);
}
YIntervalSeriesCollection dataset = new YIntervalSeriesCollection();
dataset.addSeries(sérieHPl);
// dataset.setDomainIsPointsInTime(true);
return dataset;
}
Code: Select all
private static JFreeChart createYIntervalChart(IntervalXYDataset dataset, String période)
{
// Create the chart ...
chart = ChartFactory.createScatterPlot
( "Consommation d'électricité", // chart title
période, // domain axis label - X : Time
"Puissance - KW", // range axis label - Y : Value
dataset, // data
PlotOrientation.VERTICAL,
true, // Include legend ?
true, // Use tooltips ?
false // Configure chart to generate URLs ?
);
// Here some customization of the chart ...
chart.setBackgroundPaint(Color.lightGray);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.darkGray);
plot.setRangeGridlinePaint(Color.darkGray);
plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 5.0, 5.0));
// plot.setRenderer(new YIntervalRenderer());
// YIntervalRenderer rendu = new YIntervalRenderer();
XYItemRenderer xyitemRend = plot.getRenderer();
if (xyitemRend instanceof XYLineAndShapeRenderer)
{
XYLineAndShapeRenderer xyLSRend = (XYLineAndShapeRenderer) xyitemRend;
xyLSRend.setBaseShapesVisible(true);
xyLSRend.setBaseShapesFilled(false);
}
ValueAxis domainAxis = new DateAxis("Une année");
// Exception : org.jfree.chart.axis.NumberAxis cannot be cast to org.jfree.chart.axis.DateAxis
/* DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(formateurDeDate2);
*/
TextTitle titreGraphique = chart.getTitle();
// titreGraphique.setFont(new Font(? ?)); // Normal
return chart;
}
Oeps ! I had show you a picture of the chart, but I see it has to be accessible via http ([img]http://image_url[/img]); it cannot from my "Mydocuments" folder in the HDD op my PC ...[img]C:\\Users\\....png[/img]
But I had like to have a domain axis with month dates (jan feb mar ...) instead of numbers of the week in the year (1 2 3 ... 52). How to achieve it ?
How to create a
Code: Select all
TimeSeriesCollection dataset = new TimeSeriesCollection()
dataset.addSeries(serieHPl);
In 'createDataset_Sem(...)', I tried
Code: Select all
sérieHPl.add(new Week(noDeSem, année), ...
Is it possible ?No suitable method found for add(Week,double,double,double)
And eventually this : How to get smaller pads for the max and min values of each vertical line ? (XYLineAndShapeRenderer rendu hereabove + ...)
Thanks in advance for your help.