Skip to content
Snippets Groups Projects
Commit 36196259 authored by Tim Molter's avatar Tim Molter
Browse files

bug fix: hundreds of series on plot null pointer exception

parent c9a6c18d
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ import javax.swing.tree.TreeSelectionModel; ...@@ -30,6 +30,7 @@ import javax.swing.tree.TreeSelectionModel;
import com.xeiam.xchart.XChartPanel; import com.xeiam.xchart.XChartPanel;
import com.xeiam.xchart.demo.charts.Example1; import com.xeiam.xchart.demo.charts.Example1;
import com.xeiam.xchart.demo.charts.Example10;
import com.xeiam.xchart.demo.charts.Example2; import com.xeiam.xchart.demo.charts.Example2;
import com.xeiam.xchart.demo.charts.Example3; import com.xeiam.xchart.demo.charts.Example3;
import com.xeiam.xchart.demo.charts.Example4; import com.xeiam.xchart.demo.charts.Example4;
...@@ -158,6 +159,9 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { ...@@ -158,6 +159,9 @@ public class XChartDemo extends JPanel implements TreeSelectionListener {
chart = new DefaultMutableTreeNode(new ChartInfo("Example9 - Extensive chart customization", new Example9().getChart())); chart = new DefaultMutableTreeNode(new ChartInfo("Example9 - Extensive chart customization", new Example9().getChart()));
category.add(chart); category.add(chart);
chart = new DefaultMutableTreeNode(new ChartInfo("Example10 - Plots Hundreds of Series on One Plot", new Example10().getChart()));
category.add(chart);
} }
/** /**
......
/**
* Copyright 2011-2013 Xeiam LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xeiam.xchart.demo.charts;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SeriesColor;
import com.xeiam.xchart.SeriesLineStyle;
import com.xeiam.xchart.SeriesMarker;
import com.xeiam.xchart.SwingWrapper;
/**
* Plots Hundreds of Series on One Plot
*
* @author timmolter
*/
public class Example10 implements ExampleChart {
public static void main(String[] args) {
ExampleChart exampleChart = new Example10();
Chart chart = exampleChart.getChart();
new SwingWrapper(chart).displayChart();
}
@Override
public Chart getChart() {
// Create Chart
Chart chart = new Chart(800, 600);
// Customize Chart
chart.setTitle("Example10");
chart.setXAxisTitle("X");
chart.setYAxisTitle("Y");
chart.setLegendVisible(false);
for (int i = 0; i < 200; i++) {
Series series = chart.addSeries("", new double[] { Math.random(), Math.random() }, new double[] { Math.random(), Math.random() });
series.setLineColor(SeriesColor.BLUE);
series.setLineStyle(SeriesLineStyle.SOLID);
series.setMarker(SeriesMarker.CIRCLE);
series.setMarkerColor(SeriesColor.BLUE);
}
return chart;
}
}
...@@ -62,16 +62,18 @@ public class SeriesColorMarkerLineStyleCycler { ...@@ -62,16 +62,18 @@ public class SeriesColorMarkerLineStyleCycler {
// 2. Marker // 2. Marker
for (SeriesMarker seriesMarker : EnumSet.allOf(SeriesMarker.class)) { for (SeriesMarker seriesMarker : EnumSet.allOf(SeriesMarker.class)) {
if (seriesMarker.getIndex() >= 0) { // skip Marker.NONE if (seriesMarker.getIndex() >= 0) { // skip SeriesMarker.NONE
seriesMarkerMap.put(seriesMarker.getIndex(), seriesMarker); seriesMarkerMap.put(seriesMarker.getIndex(), seriesMarker);
} }
} }
// 3. Stroke // 3. Stroke
for (SeriesLineStyle seriesLineStyle : EnumSet.allOf(SeriesLineStyle.class)) { for (SeriesLineStyle seriesLineStyle : EnumSet.allOf(SeriesLineStyle.class)) {
if (seriesLineStyle.getIndex() >= 0) { // skip SeriesLineStyle.NONE
seriesLineStyleMap.put(seriesLineStyle.getIndex(), seriesLineStyle); seriesLineStyleMap.put(seriesLineStyle.getIndex(), seriesLineStyle);
} }
} }
}
/** /**
* Get the next SeriesColorMarkerLineStyle * Get the next SeriesColorMarkerLineStyle
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment