Skip to content
Snippets Groups Projects
Commit 504956fe authored by Tim Molter's avatar Tim Molter
Browse files
parent f9db1696
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ import com.xeiam.xchart.demo.charts.line.LineChart01;
import com.xeiam.xchart.demo.charts.line.LineChart02;
import com.xeiam.xchart.demo.charts.line.LineChart03;
import com.xeiam.xchart.demo.charts.line.LineChart04;
import com.xeiam.xchart.demo.charts.line.LineChart05;
import com.xeiam.xchart.demo.charts.scatter.ScatterChart01;
import com.xeiam.xchart.demo.charts.scatter.ScatterChart02;
import com.xeiam.xchart.demo.charts.scatter.ScatterChart03;
......@@ -157,7 +158,10 @@ public class XChartDemo extends JPanel implements TreeSelectionListener {
chart = new DefaultMutableTreeNode(new ChartInfo("LineChart03 - Extensive Chart Customization", new LineChart03().getChart()));
category.add(chart);
chart = new DefaultMutableTreeNode(new ChartInfo("LineChart04 - Plots Hundreds of Series on One Plot", new LineChart04().getChart()));
chart = new DefaultMutableTreeNode(new ChartInfo("LineChart04 - Hundreds of Series on One Plot", new LineChart04().getChart()));
category.add(chart);
chart = new DefaultMutableTreeNode(new ChartInfo("LineChart05 - Scatter and Line", new LineChart05().getChart()));
category.add(chart);
// Scatter category
......
......@@ -24,7 +24,7 @@ import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart;
/**
* Plots Hundreds of Series on One Plot
* Hundreds of Series on One Plot
*/
public class LineChart04 implements ExampleChart {
......@@ -48,7 +48,7 @@ public class LineChart04 implements ExampleChart {
chart.getStyleManager().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 series = chart.addSeries("A", new double[] { Math.random(), Math.random() }, new double[] { Math.random(), Math.random() });
series.setLineColor(SeriesColor.BLUE);
series.setLineStyle(SeriesLineStyle.SOLID);
series.setMarker(SeriesMarker.CIRCLE);
......
/**
* 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.line;
import java.awt.Color;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SeriesLineStyle;
import com.xeiam.xchart.SeriesMarker;
import com.xeiam.xchart.StyleManager.LegendPosition;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart;
/**
* Scatter and Line
* <p>
* Demonstrates the following:
* <ul>
* <li>Customizing the series style properties
* <li>Scatter and Line overlay
* <li>Logarithmic Y-Axis
*/
public class LineChart05 implements ExampleChart {
public static void main(String[] args) {
ExampleChart exampleChart = new LineChart05();
Chart chart = exampleChart.getChart();
new SwingWrapper(chart).displayChart();
}
@Override
public Chart getChart() {
// Create Chart
Chart chart = new Chart(800, 600);
// Customize Chart
chart.setChartTitle("LineChart05");
chart.setXAxisTitle("X");
chart.setYAxisTitle("Y");
chart.getStyleManager().setLegendPosition(LegendPosition.InsideSW);
double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5, 6 };
double[] yData = new double[] { 106, 44, 26, 10, 7.5, 3.4, .88 };
double[] yData2 = new double[] { 102, 49, 23.6, 11.3, 5.4, 2.6, 1.25 };
Series series = chart.addSeries("A", xData, yData);
series.setLineStyle(SeriesLineStyle.NONE);
series.setMarker(SeriesMarker.DIAMOND);
series.setMarkerColor(Color.BLACK);
Series series2 = chart.addSeries("B", xData, yData2);
series2.setMarker(SeriesMarker.NONE);
series2.setLineStyle(SeriesLineStyle.DASH_DASH);
series2.setLineColor(Color.BLACK);
chart.getStyleManager().setYAxisLogarithmic(true);
chart.getStyleManager().setYAxisMin(0.01);
chart.getStyleManager().setYAxisMax(1000);
chart.getStyleManager().setXAxisMin(-2);
chart.getStyleManager().setXAxisMax(8);
return chart;
}
}
......@@ -77,6 +77,9 @@ public class Series {
*/
public Series(String name, Collection<?> xData, AxisType xAxisType, Collection<Number> yData, AxisType yAxisType, Collection<Number> errorBars, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) {
if (name == null || name.length() < 1) {
throw new IllegalArgumentException("Series name cannot be null or zero-length!!!");
}
this.name = name;
this.xData = xData;
this.yData = yData;
......
......@@ -738,7 +738,7 @@ public class StyleManager {
this.xAxisMin = xAxisMin;
}
public Double getxAxisMin() {
public Double getXAxisMin() {
return xAxisMin;
}
......@@ -748,7 +748,7 @@ public class StyleManager {
this.xAxisMax = xAxisMax;
}
public Double getxAxisMax() {
public Double getXAxisMax() {
return xAxisMax;
}
......
......@@ -79,14 +79,14 @@ public abstract class AxisTickCalculator {
}
}
// override min and maxValue if specified
if (axisDirection == Direction.X && styleManager.getxAxisMin() != null) {
overrideMinValue = new BigDecimal(styleManager.getxAxisMin());
if (axisDirection == Direction.X && styleManager.getXAxisMin() != null) {
overrideMinValue = new BigDecimal(styleManager.getXAxisMin());
}
if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) {
overrideMinValue = new BigDecimal(styleManager.getYAxisMin());
}
if (axisDirection == Direction.X && styleManager.getxAxisMax() != null) {
overrideMaxValue = new BigDecimal(styleManager.getxAxisMax());
if (axisDirection == Direction.X && styleManager.getXAxisMax() != null) {
overrideMaxValue = new BigDecimal(styleManager.getXAxisMax());
}
if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) {
overrideMaxValue = new BigDecimal(styleManager.getYAxisMax());
......
......@@ -101,17 +101,11 @@ public class PlotContentBarChart extends PlotContent {
// figure out the general form of the chart
int chartForm = 1; // 1=positive, -1=negative, 0=span
if (yMin.compareTo(BigDecimal.ZERO) > 0 && yMax.compareTo(BigDecimal.ZERO) > 0) {
// positive chart
chartForm = 1;
System.out.println("positive chart");
chartForm = 1; // positive chart
} else if (yMin.compareTo(BigDecimal.ZERO) < 0 && yMax.compareTo(BigDecimal.ZERO) < 0) {
// negative chart
chartForm = -1;
System.out.println("negative chart");
chartForm = -1; // negative chart
} else {
// span chart
chartForm = 0;
System.out.println("span chart");
chartForm = 0;// span chart
}
Iterator<?> categoryItr = categories.iterator();
......
......@@ -64,32 +64,34 @@ public class PlotContentLineChart extends PlotContent {
Collection<?> xData = series.getxData();
BigDecimal xMin = getChartPainter().getAxisPair().getxAxis().getMin();
BigDecimal xMax = getChartPainter().getAxisPair().getxAxis().getMax();
if (getChartPainter().getStyleManager().isXAxisLogarithmic()) {
xMin = new BigDecimal(Math.log10(xMin.doubleValue()));
xMax = new BigDecimal(Math.log10(xMax.doubleValue()));
}
Collection<Number> yData = series.getyData();
BigDecimal yMin = getChartPainter().getAxisPair().getyAxis().getMin();
BigDecimal yMax = getChartPainter().getAxisPair().getyAxis().getMax();
if (getChartPainter().getStyleManager().isYAxisLogarithmic()) {
yMin = new BigDecimal(Math.log10(yMin.doubleValue()));
yMax = new BigDecimal(Math.log10(yMax.doubleValue()));
}
// override min and maxValue if specified
if (getChartPainter().getStyleManager().getxAxisMin() != null) {
xMin = new BigDecimal(getChartPainter().getStyleManager().getxAxisMin());
if (getChartPainter().getStyleManager().getXAxisMin() != null) {
xMin = new BigDecimal(getChartPainter().getStyleManager().getXAxisMin());
}
if (getChartPainter().getStyleManager().getYAxisMin() != null) {
yMin = new BigDecimal(getChartPainter().getStyleManager().getYAxisMin());
}
if (getChartPainter().getStyleManager().getxAxisMax() != null) {
xMin = new BigDecimal(getChartPainter().getStyleManager().getxAxisMax());
if (getChartPainter().getStyleManager().getXAxisMax() != null) {
xMax = new BigDecimal(getChartPainter().getStyleManager().getXAxisMax());
}
if (getChartPainter().getStyleManager().getYAxisMax() != null) {
yMax = new BigDecimal(getChartPainter().getStyleManager().getYAxisMax());
}
// logarithmic
if (getChartPainter().getStyleManager().isXAxisLogarithmic()) {
xMin = new BigDecimal(Math.log10(xMin.doubleValue()));
xMax = new BigDecimal(Math.log10(xMax.doubleValue()));
}
if (getChartPainter().getStyleManager().isYAxisLogarithmic()) {
yMin = new BigDecimal(Math.log10(yMin.doubleValue()));
yMax = new BigDecimal(Math.log10(yMax.doubleValue()));
}
Collection<Number> errorBars = series.getErrorBars();
int previousX = Integer.MIN_VALUE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment