0

I´m trying to add a second ValueAxis to the JFreeChart. I have two TimeSeries who have exactly the same x-values. the first dataset should attach to the left Y-Axis and the second dataset to the right Y-Axis.

It works, but there are two blue y-value axis of the second Database value in the chart. One belong to the left Y-Axis (blue one - nearly zero) and one to the right. Otherwise the values of the 1. values of the database are not correct displayed. the values of the red are not correct displayed

[Here is the value displaying is correct] But there is additional the blue one at zero value? (https://i.stack.imgur.com/rPv3C.png)

After rezooming there is this displaying enter image description here The one which is corresponding to the right y-Axis is gone??

Zooming the blue one: The Y-Values to the left and the right are now the same? :( enter image description here

public Graphen(final String title)
    {
        super(title);

        final String chartTitel = "PV Daten";
        resultSet = Verbinden_thread_Datenbank.DatenAbfrage3();
        TimeSeriesCollection TSC = new TimeSeriesCollection();
        XYSeriesCollection XYSC = new XYSeriesCollection();
       
        TimeSeries s = Batterieleistung(resultSet);
        TSC.addSeries(s);
        TemperaturKesselResultSet = Verbinden_thread_Datenbank.DatenAbfrage2();
         
        TimeSeries s2 = TemperaturKessel(TemperaturKesselResultSet);
        TSC.addSeries(s2);



        final JFreeChart chart = ChartFactory.createTimeSeriesChart("PV Daten", "Uhrzeit","Batteriespannung", TSC);   ///new TimeSeriesCollection(s)

        SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss");
        f.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));

        XYPlot plot = (XYPlot) chart.getXYPlot();
        ValueAxis valueAxis1 = (ValueAxis) plot.getRangeAxis(0);  // 1
       /////
    //    plot.setDataset(1,chart.getXYPlot().getDataset(0));      // 0   
        valueAxis1.setRange(-5000.0, 5000.0);
     //  plot.mapDatasetToRangeAxis(1, 1);
/////        
  
      final NumberAxis axis3 = new NumberAxis("Temperatur Kessel");
         plot.setRangeAxis(1,axis3);         // 2
 
      ValueAxis valueAxis2 = (ValueAxis) plot.getRangeAxis(1);       // 2      
    valueAxis2.setRange(38.0, 50.0);
      
//      
  
         
        plot.setDataset(1,chart.getXYPlot().getDataset(0)) ;                     ///(1,chart.getXYPlot().getDataset(0));      // 0   
        valueAxis2.setRange(38.0, 50.0);
        plot.mapDatasetToRangeAxis(1, 1);
   //     plot.setDataset(0, chart.getXYPlot().getDataset(0));              // (1,chart.getXYPlot().getDataset(0)); 

//    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    //    r.setDefaultShapesVisible(true);

    DateAxis domain = (DateAxis) plot.getDomainAxis();
        domain.setDateFormatOverride(f);
        domain.setVerticalTickLabels(true);

   

  
        final ChartPanel panel = new ChartPanel(chart);
     
        panel.setPreferredSize(new java.awt.Dimension(1600,800));
        panel.setRangeZoomable(true);
        panel.setDomainZoomable(true);
        setContentPane(panel);
/*

CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(
    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
*/
}

The x-Values of the two TimeSeries are completely the same.

  • A similar problem is examined [here](https://stackoverflow.com/a/39202162/230513); more [here](https://stackoverflow.com/search?tab=votes&q=%5bjfreechart%5d%20mapDatasetToRangeAxis&searchOn=3). – trashgod May 29 '23 at 00:16
  • If this is not a duplicate, please [edit] your question to include a [mre] that shows your revised approach. – trashgod May 31 '23 at 16:52

0 Answers0