How to make a this kind of barchart ->
How to make a this kind of barchart ->
Hi,
I would like to make a barchart in which the weidth of a bar depends on the x scale values he represents. For example:
if my x scale has a lenght of 4 meters with 3 bars( We do not pay attention to the y value).
- the first bar would have a weidth of 2 (because all the y values between 0 and 2 are the same).
- the second would have a weidth of 1.5
- the thirs would have a weidth of 0.5
In the barcharts I know I have to specify in the legend that the first bar represents value between 0 and 2... and all the bars have the same weidth...
Sorry if my explications are confused..
Thanks a lot
Mat
Mat
I would like to make a barchart in which the weidth of a bar depends on the x scale values he represents. For example:
if my x scale has a lenght of 4 meters with 3 bars( We do not pay attention to the y value).
- the first bar would have a weidth of 2 (because all the y values between 0 and 2 are the same).
- the second would have a weidth of 1.5
- the thirs would have a weidth of 0.5
In the barcharts I know I have to specify in the legend that the first bar represents value between 0 and 2... and all the bars have the same weidth...
Sorry if my explications are confused..
Thanks a lot
Mat
Mat
Re: How to make a this kind of barchart ->
Maybe a horizontal stacked bar chart with 3 series and just one category? I'm not sure I fully understand your description though...can you supply an example in PNG or GIF format?
Regards,
DG.
Regards,
DG.
Re: How to make a this kind of barchart ->
Hi
thanks for your reply
here is an example of what I would like
http://perso.wanadoo.fr/mathieu.rossier/example.htm
Mat
thanks for your reply
here is an example of what I would like
http://perso.wanadoo.fr/mathieu.rossier/example.htm
Mat
Re: How to make a this kind of barchart ->
I tried the link but it seems to be missing a couple of images.
Re: How to make a this kind of barchart ->
Sorry
I did it quickly with word and I saved as a html doc... With my browser it works... (IE 6.0) maybe here is the problem..
I put directly the word document
http://perso.wanadoo.fr/mathieu.rossier/example.doc
if you have IE it should works otherwise I will try tu make a gift but I do not how yet..
Mat
I did it quickly with word and I saved as a html doc... With my browser it works... (IE 6.0) maybe here is the problem..
I put directly the word document
http://perso.wanadoo.fr/mathieu.rossier/example.doc
if you have IE it should works otherwise I will try tu make a gift but I do not how yet..
Mat
Re: How to make a this kind of barchart ->
This link shows the type of thing you can do with the VerticalXYBarChart:
http://www.object-refinery.com/jfreecha ... art100.png
But it requires you to create your own dataset that implements the IntervalXYDataset interface, because there isn't a ready-made implementation available yet. It is not very hard to do, but a lot of people seem to struggle with it.
Regards,
DG
http://www.object-refinery.com/jfreecha ... art100.png
But it requires you to create your own dataset that implements the IntervalXYDataset interface, because there isn't a ready-made implementation available yet. It is not very hard to do, but a lot of people seem to struggle with it.
Regards,
DG
Re: How to make a this kind of barchart ->
The pictures you showed me is exactly what I need...
I'll try to do it...
Thanks a lot
Mat
I'll try to do it...
Thanks a lot
Mat
Re: How to make a this kind of barchart ->
Here is the code I used (first the demo application, followed by the quick-and-dirty dataset class, sorry about the formatting). I think it will compile in 0.9.1, but I used the CVS code so I can't guarantee it:
package com.jrefinery.chart.demo;
import com.jrefinery.data.IntervalXYDataset;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.XYPlot;
import com.jrefinery.chart.HorizontalNumberAxis;
import java.awt.Paint;
import java.awt.Color;
import java.awt.Stroke;
import java.awt.BasicStroke;
/**
* A simple demonstration application showing how to create a vertical bar chart.
*/
public class VerticalXYBarChartDemo extends ApplicationFrame {
/** The data. */
protected IntervalXYDataset data;
/**
* Default constructor.
*/
public VerticalXYBarChartDemo(String title) {
super(title);
// create a dataset...
IntervalXYDataset dataset = new SimpleIntervalXYDataset();
// create the chart...
JFreeChart chart = ChartFactory.createVerticalXYBarChart(
"Sample", // chart title
"X", // domain axis label
"Y", // range axis label
dataset, // data
true // include legend
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
XYPlot plot = chart.getXYPlot();
plot.setDomainAxis(new HorizontalNumberAxis("X"));
// OPTIONAL CUSTOMISATION COMPLETED.
// add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(chart);
this.setContentPane(chartPanel);
}
/**
* Starting point for the demonstration application.
*/
public static void main(String[] args) {
VerticalXYBarChartDemo demo = new VerticalXYBarChartDemo("Vertical XY Bar Chart Demo");
demo.pack();
demo.setVisible(true);
}
}
**********************************
package com.jrefinery.chart.demo;
import com.jrefinery.data.IntervalXYDataset;
import com.jrefinery.data.DatasetChangeListener;
/**
* A quick and dirty implementation.
*/
public class SimpleIntervalXYDataset implements IntervalXYDataset {
Double[] xStart = new Double[3];
Double[] xEnd = new Double[3];
Double[] y = new Double[3];
public SimpleIntervalXYDataset() {
xStart[0] = new Double(0.0);
xStart[1] = new Double(2.0);
xStart[2] = new Double(3.5);
xEnd[0] = new Double(2.0);
xEnd[1] = new Double(3.5);
xEnd[2] = new Double(4.0);
y[0] = new Double(3.0);
y[1] = new Double(4.5);
y[2] = new Double(2.5);
}
/**
* Returns the number of series in the dataset.
* @return The number of series in the dataset.
*/
public int getSeriesCount() {
return 1;
}
/**
* Returns the name of a series.
* @param series The series (zero-based index).
*/
public String getSeriesName(int series) {
return "Series 1";
}
/**
* Returns the number of items in a series.
* @param series The series (zero-based index).
* @return The number of items within a series.
*/
public int getItemCount(int series) {
return 3;
}
/**
* Returns the x-value for an item within a series.
* <P>
* The implementation is responsible for ensuring that the x-values are presented in ascending
* order.
* @param series The series (zero-based index).
* @param item The item (zero-based index).
* @return The x-value for an item within a series.
*/
public Number getXValue(int series, int item) {
return xStart[item];
}
/**
* Returns the y-value for an item within a series.
* @param series The series (zero-based index).
* @param item The item (zero-based index).
* @return The y-value for an item within a series.
*/
public Number getYValue(int series, int item) {
return y[item];
}
/**
* Returns the starting X value for the specified series and item.
* @param series The series (zero-based index);
* @param item The item within a series (zero-based index).
*/
public Number getStartXValue(int series, int item) {
return xStart[item];
}
/**
* Returns the ending X value for the specified series and item.
* @param series The series (zero-based index);
* @param item The item within a series (zero-based index).
*/
public Number getEndXValue(int series, int item) {
return xEnd[item];
}
/**
* Returns the starting Y value for the specified series and item.
* @param series The series (zero-based index);
* @param item The item within a series (zero-based index).
*/
public Number getStartYValue(int series, int item) {
return y[item];
}
/**
* Returns the ending Y value for the specified series and item.
* @param series The series (zero-based index);
* @param item The item within a series (zero-based index).
*/
public Number getEndYValue(int series, int item) {
return y[item];
}
/**
* Registers an object for notification of changes to the dataset.
* @param listener The object to register.
*/
public void addChangeListener(DatasetChangeListener listener) {}
/**
* Deregisters an object for notification of changes to the dataset.
* @param listener The object to deregister.
*/
public void removeChangeListener(DatasetChangeListener listener) {}
}
package com.jrefinery.chart.demo;
import com.jrefinery.data.IntervalXYDataset;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.XYPlot;
import com.jrefinery.chart.HorizontalNumberAxis;
import java.awt.Paint;
import java.awt.Color;
import java.awt.Stroke;
import java.awt.BasicStroke;
/**
* A simple demonstration application showing how to create a vertical bar chart.
*/
public class VerticalXYBarChartDemo extends ApplicationFrame {
/** The data. */
protected IntervalXYDataset data;
/**
* Default constructor.
*/
public VerticalXYBarChartDemo(String title) {
super(title);
// create a dataset...
IntervalXYDataset dataset = new SimpleIntervalXYDataset();
// create the chart...
JFreeChart chart = ChartFactory.createVerticalXYBarChart(
"Sample", // chart title
"X", // domain axis label
"Y", // range axis label
dataset, // data
true // include legend
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
XYPlot plot = chart.getXYPlot();
plot.setDomainAxis(new HorizontalNumberAxis("X"));
// OPTIONAL CUSTOMISATION COMPLETED.
// add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(chart);
this.setContentPane(chartPanel);
}
/**
* Starting point for the demonstration application.
*/
public static void main(String[] args) {
VerticalXYBarChartDemo demo = new VerticalXYBarChartDemo("Vertical XY Bar Chart Demo");
demo.pack();
demo.setVisible(true);
}
}
**********************************
package com.jrefinery.chart.demo;
import com.jrefinery.data.IntervalXYDataset;
import com.jrefinery.data.DatasetChangeListener;
/**
* A quick and dirty implementation.
*/
public class SimpleIntervalXYDataset implements IntervalXYDataset {
Double[] xStart = new Double[3];
Double[] xEnd = new Double[3];
Double[] y = new Double[3];
public SimpleIntervalXYDataset() {
xStart[0] = new Double(0.0);
xStart[1] = new Double(2.0);
xStart[2] = new Double(3.5);
xEnd[0] = new Double(2.0);
xEnd[1] = new Double(3.5);
xEnd[2] = new Double(4.0);
y[0] = new Double(3.0);
y[1] = new Double(4.5);
y[2] = new Double(2.5);
}
/**
* Returns the number of series in the dataset.
* @return The number of series in the dataset.
*/
public int getSeriesCount() {
return 1;
}
/**
* Returns the name of a series.
* @param series The series (zero-based index).
*/
public String getSeriesName(int series) {
return "Series 1";
}
/**
* Returns the number of items in a series.
* @param series The series (zero-based index).
* @return The number of items within a series.
*/
public int getItemCount(int series) {
return 3;
}
/**
* Returns the x-value for an item within a series.
* <P>
* The implementation is responsible for ensuring that the x-values are presented in ascending
* order.
* @param series The series (zero-based index).
* @param item The item (zero-based index).
* @return The x-value for an item within a series.
*/
public Number getXValue(int series, int item) {
return xStart[item];
}
/**
* Returns the y-value for an item within a series.
* @param series The series (zero-based index).
* @param item The item (zero-based index).
* @return The y-value for an item within a series.
*/
public Number getYValue(int series, int item) {
return y[item];
}
/**
* Returns the starting X value for the specified series and item.
* @param series The series (zero-based index);
* @param item The item within a series (zero-based index).
*/
public Number getStartXValue(int series, int item) {
return xStart[item];
}
/**
* Returns the ending X value for the specified series and item.
* @param series The series (zero-based index);
* @param item The item within a series (zero-based index).
*/
public Number getEndXValue(int series, int item) {
return xEnd[item];
}
/**
* Returns the starting Y value for the specified series and item.
* @param series The series (zero-based index);
* @param item The item within a series (zero-based index).
*/
public Number getStartYValue(int series, int item) {
return y[item];
}
/**
* Returns the ending Y value for the specified series and item.
* @param series The series (zero-based index);
* @param item The item within a series (zero-based index).
*/
public Number getEndYValue(int series, int item) {
return y[item];
}
/**
* Registers an object for notification of changes to the dataset.
* @param listener The object to register.
*/
public void addChangeListener(DatasetChangeListener listener) {}
/**
* Deregisters an object for notification of changes to the dataset.
* @param listener The object to deregister.
*/
public void removeChangeListener(DatasetChangeListener listener) {}
}
Re: How to make a this kind of barchart ->
Hi,
I tried your example and it works perfectly with what I want..
There is still one thing I did not arrive to set up..
The legend of the serie:
How can I modify it
Thanks
Mat
I tried your example and it works perfectly with what I want..
There is still one thing I did not arrive to set up..
The legend of the serie:
How can I modify it
Thanks
Mat