Third bar chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Chavadam
Posts: 4
Joined: Sat Mar 03, 2007 4:12 pm
Location: Belgium

Third bar chart

Post by Chavadam » Mon Mar 24, 2014 6:38 pm

Dear JFreeChart users, dear Dave,

I reach the end of an application including a nice chart panel of JFreeChart (v.1.0.10) with
- two (I had like three) series of the XYSeriesCollection class. One (I had like two) plots are of XYBarRenderer and another one of StandardXYItemRenderer.
- a variable number of vertical markers of different colors in the background, dynamically settable and removable.
[img]How%20to%20attach%20a%20picture%20file%20in%20a%20folder%20of%20my%20computer%20(no%20http://)?[/img].
The three data sets correspond to on-peak (XYBarRenderer), off-peak (StandardXYItemRenderer) and both ( XYBarRenderer preferably and of another color) power values.

Q1: What do I have to do to display a third plot (in a third color) ?

Code: Select all

    public JFreeChart créerGraphique(ArrayList[] listes_PuissEnerg)
    {
        NumberAxis axeAbcisses = new NumberAxis("Puissance - KW");      // Domain
        // axeAbcisses.setTickMarkPosition
        ValueAxis axeOrdonnées = new NumberAxis("Energie - MWH");       // Range
        IntervalXYDataset donnéesHPl, donnéesHPlHCr, donnéesHCr;
        XYItemRenderer renduHPl, renduHPlHCr, renduHCr;
        XYPlot plot;
        
        if (listes_PuissEnerg != null)
        {
            donnéesHPlHCr = createDataset(listes_PuissEnerg[HPLEINESETCREUSES_IDX], HPLEINESETCREUSES_IDX);
            renduHPlHCr = new XYBarRenderer(0.10);
            renduHPlHCr.setBaseStroke(new BasicStroke(0.5f));
            renduHPlHCr.setBaseToolTipGenerator(
                    new StandardXYToolTipGenerator(
                            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                                    new DecimalFormat("0.0"), new DecimalFormat("0.000") ) );
            plot = new XYPlot(donnéesHPlHCr, axeAbcisses, axeOrdonnées, renduHPlHCr);

            donnéesHPl = createDataset(listes_PuissEnerg[HPLEINES_IDX], HPLEINES_IDX);
            renduHPl = new XYBarRenderer(0.10);
            renduHPl.setBaseStroke(new BasicStroke(0.5f));
            renduHPl.setBaseToolTipGenerator(
                    new StandardXYToolTipGenerator(
                            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                                    new DecimalFormat("0.0"), new DecimalFormat("0.000") ) );
            plot = new XYPlot(donnéesHPl, axeAbcisses, axeOrdonnées, renduHPl);
           
            donnéesHCr = createDataset(listes_PuissEnerg[HCREUSES_IDX], HCREUSES_IDX);
            renduHCr = new StandardXYItemRenderer();
            renduHCr.setBaseToolTipGenerator(
                    new StandardXYToolTipGenerator(
                            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                                    new DecimalFormat("0.0"), new DecimalFormat("0.000") ) );
            plot.setDataset(1, donnéesHCr);
            plot.setRenderer(1, renduHCr);
            plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
            plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
            plot.setDomainCrosshairVisible(true);
            plot.setRangeCrosshairVisible(true);
            plot.setForegroundAlpha(0.675f);

            // Set the domain axis (X) to display integers only ...
            axeAbcisses = (NumberAxis) plot.getDomainAxis();
            axeAbcisses.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            // Set the range axis (Y) to display integers only ...
            axeOrdonnées = (NumberAxis) plot.getRangeAxis();
            axeOrdonnées.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        } else
        {   // Very first graph display, before first dataset filling.
            plot = new XYPlot(null, axeAbcisses, axeOrdonnées, null);
        }
        
        // Add vertical markers ...
Q2: Chart of XYBarRenderer : Which instruction to use to get thinner vertical strips with XYBarRenderer ?
For each of the two datasets corresponding to the chart of the picture, I have about 3 x 150 values on the domain axis, ending respectively and randomly with ...,00 , ...,50 and ...,60. I don't know why; these are input data from a provider to take as are. One can observe that JFreeChart treat them such a way that it displays 3 layers of slighly shifted bar sets and of slighly different red intensities.

Many thanks by advance
Skype : Chavadam

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Third bar chart

Post by david.gilbert » Sat Mar 29, 2014 12:24 pm

It's a bit hard to answer without seeing the chart image. You need to host it somewhere on the web then provide a link to it.

ClusteredXYBarRenderer is designed to show multiple data series (having the same x-values) as bars side-by-side. Maybe that's what you need for Q1.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked