From: SourceForge.net <no...@so...> - 2008-10-02 00:14:54
|
Bugs item #2092643, was opened at 2008-09-04 02:17 Message generated for change (Settings changed) made by richotero You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115494&aid=2092643&group_id=15494 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: None Status: Open Resolution: Wont Fix Priority: 5 Private: No Submitted By: rotero (richotero) Assigned to: David Gilbert (mungady) >Summary: Malformed line using XYLineChart (code to replicate) Initial Comment: Thank you for the great product! I wanted to let you know that I've noticed that a graph can show the data correctly, as the lower section of the attached image shows, but the line can become malformed if the axis choices are switched. This is shown by the upper section of the attached image. I use the same arrays of data for each graph. The code I use to generate the graph has been attached. I tried upgrading to your latest released version, jfreechart-1.0.10.jar, but the problem still occurs. Thank you again for your help! Richard // Find the array associated with the passed in key // within the passed in HashMap // Return the double[] contained in the map for the // requested variable private double[] selectOutputVariable(HashMap outputStorage, String variableLabel) { DoubleArray darray = null; try { if (variableLabel.equals("Time (s)")) { darray = (DoubleArray) outputStorage.get("time (s)"); } else if // snip } // This function creates the graph using jfreegraph private void createGraphBMouseReleased(java.awt.event.MouseEvent evt) { // the strings from two combo boxes showing // what values should go on the X or Y axis String xAxis = (String) xAxisCB.getSelectedItem(); String yAxis = (String) yAxisCB.getSelectedItem(); // pesstOutput is a HashMap containing the data // arrays that would be used for the graph if (pesstOutput != null) { double[] xData, yData; int i; xData = selectOutputVariable(pesstOutput, xAxis); yData = selectOutputVariable(pesstOutput, yAxis); JFrame graphFrame = new JFrame(""); graphFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); final XYSeries series1 = new XYSeries(""); for(i=0; i<xData.length; i++) { series1.add(xData[i], yData[i]); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); final JFreeChart chart = ChartFactory.createXYLineChart( "", // chart title xAxis, // x axis label yAxis, // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); BufferedImage image = chart.createBufferedImage(750, 350); JLabel label = new JLabel(); label.setIcon(new ImageIcon(image)); graphFrame.getContentPane().add(label); graphFrame.pack(); graphFrame.setVisible(true); } else { // snip } } ---------------------------------------------------------------------- Comment By: rotero (richotero) Date: 2008-10-01 19:11 Message: I believe that this is not related to the ordering of the items in the dataset. To provide evidence of this; I've written a program that replicates the problem. Two graphs are printed by the program. One with all but the last 10 data points and the second will all 190 data points. You can see the difference between the two graphs. I know that bug finding through user feedback can be a tough game so I hope that this example program makes it easier for you to replicate the behavior I'm seeing. --------------------------------------- import javax.swing.JFrame; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** * * @author richard */ public class NewMain { public static void main(String[] args) { double[] xData = {48.801, 48.757, 48.713, 48.668, 48.624, 48.580, 48.535, 48.491, 48.447, 48.403, 48.359, 48.315, 48.271, 48.227, 48.183, 48.139, 48.095, 48.051, 48.008, 47.964, 47.921, 47.877, 47.834, 47.790, 47.747, 47.703, 47.660, 47.617, 47.573, 47.530, 47.487, 47.443, 47.400, 47.357, 47.314, 47.271, 47.228, 47.185, 47.142, 47.099, 47.056, 47.014, 46.971, 46.929, 46.886, 46.844, 46.801, 46.759, 46.717, 46.675, 46.633, 46.591, 46.550, 46.508, 46.466, 46.425, 46.383, 46.342, 46.301, 46.260, 46.219, 46.178, 46.137, 46.097, 46.056, 46.016, 45.975, 45.935, 45.895, 45.855, 45.815, 45.775, 45.736, 45.696, 45.657, 45.617, 45.577, 45.538, 45.498, 45.458, 45.418, 45.378, 45.338, 45.298, 45.258, 45.218, 45.178, 45.138, 45.098, 45.058, 45.018, 45.018, 44.978, 44.938, 44.898, 44.858, 44.818, 44.778, 44.738, 44.698, 44.658, 44.618, 44.579, 44.539, 44.499, 44.460, 44.420, 44.381, 44.341, 44.302, 44.263, 44.223, 44.184, 44.145, 44.106, 44.067, 44.029, 43.990, 43.951, 43.913, 43.874, 43.836, 43.798, 43.759, 43.721, 43.683, 43.645, 43.607, 43.570, 43.532, 43.494, 43.457, 43.421, 43.386, 43.352, 43.320, 43.288, 43.258, 43.229, 43.201, 43.174, 43.147, 43.122, 43.098, 43.074, 43.051, 43.029, 43.008, 42.988, 42.968, 42.949, 42.930, 42.913, 42.896, 42.879, 42.863, 42.848, 42.833, 42.818, 42.805, 42.791, 42.778, 42.766, 42.754, 42.742, 42.731, 42.720, 42.710, 42.700, 42.690, 42.681, 42.672, 42.663, 42.655, 42.647, 42.639, 42.631, 42.624, 42.617, 42.610, 43.245, 43.877, 44.505, 45.131, 45.753, 46.372, 46.987, 47.600, 48.209, 48.815}; double[] yData = {-806.41, -816.16, -825.91, -835.65, -845.38, -855.10, -864.81, -874.51, -884.21, -893.89, -903.57, -913.23, -922.89, -932.54, -942.18, -951.82, -961.44, -971.05, -980.66, -990.26, -999.84, -1009.40, -1019.00, -1028.60, -1038.10, -1047.70, -1057.20, -1066.70, -1076.20, -1085.70, -1095.30, -1104.70, -1114.20, -1123.70, -1133.20, -1142.60, -1152.10, -1161.50, -1171.00, -1180.40, -1189.80, -1199.20, -1208.60, -1218.00, -1227.40, -1236.70, -1246.10, -1255.50, -1264.80, -1274.20, -1283.50, -1292.80, -1302.10, -1311.40, -1320.70, -1330.00, -1339.30, -1348.60, -1357.80, -1367.10, -1376.30, -1385.60, -1394.80, -1404.00, -1413.20, -1422.40, -1431.60, -1440.80, -1450.00, -1459.20, -1468.40, -1477.50, -1486.70, -1495.80, -1505.00, -1514.10, -1523.20, -1532.30, -1541.40, -1550.50, -1559.60, -1568.70, -1577.70, -1586.80, -1595.90, -1604.90, -1614.00, -1623.00, -1632.00, -1641.00, -1650.00, -1650.00, -1659.00, -1668.00, -1677.00, -1686.00, -1695.00, -1703.90, -1712.90, -1721.80, -1730.70, -1739.70, -1748.60, -1757.50, -1766.40, -1775.30, -1784.20, -1793.10, -1801.90, -1810.80, -1819.70, -1828.50, -1837.30, -1846.20, -1855.00, -1863.80, -1872.60, -1881.40, -1890.20, -1899.00, -1907.80, -1916.60, -1925.30, -1934.10, -1942.80, -1951.60, -1960.30, -1969.00, -1977.70, -1986.50, -1995.20, -2003.90, -2012.50, -2021.20, -2029.90, -2038.60, -2047.20, -2055.90, -2064.50, -2073.20, -2081.80, -2090.40, -2099.10, -2107.70, -2116.30, -2124.90, -2133.50, -2142.10, -2150.70, -2159.30, -2167.90, -2176.50, -2185.10, -2193.70, -2202.30, -2210.80, -2219.40, -2228.00, -2236.50, -2245.10, -2253.70, -2262.20, -2270.80, -2279.30, -2287.90, -2296.40, -2305.00, -2313.50, -2322.00, -2330.60, -2339.10, -2347.70, -2356.20, -2364.70, -2373.20, -2381.80, -2390.30, -2398.80, -2407.40, -2415.90, -2424.50, -2433.20, -2442.00, -2451.00, -2460.10, -2469.30, -2478.60, -2488.10, -2497.70, -2507.40}; int i; JFrame partialDataGraphFrame = new JFrame(""); JFrame fullDataGraphFrame = new JFrame(""); final XYSeries partialDataSeries = new XYSeries(""); for (i = 0; i < 180; i++) { partialDataSeries.add(xData[i], yData[i]); } // Only 10 additional points are added to the graph // but it completely changes how the graph is displayed final XYSeries fullDataSeries = new XYSeries(""); for (i = 0; i < 190; i++) { fullDataSeries.add(xData[i], yData[i]); } final XYSeriesCollection partialDataset = new XYSeriesCollection(); final XYSeriesCollection fullDataset = new XYSeriesCollection(); partialDataset.addSeries(partialDataSeries); fullDataset.addSeries(fullDataSeries); final JFreeChart partialChart = ChartFactory.createXYLineChart( "Chart of partial dataset", // chart title "x-axis", // x axis label "y-axis", // y axis label partialDataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); final JFreeChart fullChart = ChartFactory.createXYLineChart( "Chart of full dataset", // chart title "x-axis", // x axis label "y-axis", // y axis label fullDataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); partialDataGraphFrame.getContentPane().add(new ChartPanel(partialChart)); fullDataGraphFrame.getContentPane().add(new ChartPanel(fullChart)); partialDataGraphFrame.pack(); fullDataGraphFrame.pack(); partialDataGraphFrame.setVisible(true); fullDataGraphFrame.setVisible(true); } } ---------------------------------------------------------------------- Comment By: David Gilbert (mungady) Date: 2008-09-23 03:28 Message: I think this is just an issue with the ordering of the items in the dataset (the renderer will plot them in the order it receives them). Rather than swap the x and y values in the dataset, perhaps you just want to change the plot orientation to PlotOrientation.HORIZONTAL? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115494&aid=2092643&group_id=15494 |