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

fixed horizontal and vertical plotting bug

parent dc7044c4
No related branches found
No related tags found
No related merge requests found
......@@ -149,6 +149,12 @@ public class AxisTick implements IChartPart {
// System.out.println("b= " + b);
tickLabels.add(format(b.doubleValue()));
int tickLabelPosition = (int) (leftMargin + ((b.doubleValue() - axis.getMin()) / (axis.getMax() - axis.getMin()) * tickSpace));
// a check if all axis data are the exact same values
if (Math.abs(axis.getMax() - axis.getMin()) / 5 == 0.0) {
tickLabelPosition = (int) (leftMargin + tickSpace / 2.0);
}
tickLocations.add(tickLabelPosition);
}
}
......@@ -162,7 +168,11 @@ public class AxisTick implements IChartPart {
// e.g. 724.1 --> 7.241 * 10 ** 2
double mantissa = gridStepHint;
int exponent = 0;
if (mantissa < 1) {
if (mantissa == 0) {
// mantissa = 0.0;
exponent = 1;
} else if (mantissa < 1) {
while (mantissa < 1) {
mantissa *= 10.0;
exponent--;
......
......@@ -60,7 +60,7 @@ public class AxisTickLabels implements IChartPart {
g.setColor(foreground);
if (axis.getDirection() == Axis.Direction.Y) {
if (axis.getDirection() == Axis.Direction.Y) { // Y-Axis
int xOffset = (int) (axis.getAxisTitle().getBounds().getX() + axis.getAxisTitle().getBounds().getWidth());
int yOffset = (int) (axis.getPaintZone().getY());
......
......@@ -75,6 +75,16 @@ public class PlotContent implements IChartPart {
int xTransform = (int) (xLeftMargin + ((xData[i] - xMin) / (xMax - xMin) * xTickSpace));
int yTransform = (int) (bounds.getHeight() - (yLeftMargin + (yData[i] - yMin) / (yMax - yMin) * yTickSpace));
// a check if all y data are the exact same values
if (Math.abs(xMax - xMin) / 5 == 0.0) {
xTransform = (int) (bounds.getWidth() / 2.0);
}
// a check if all y data are the exact same values
if (Math.abs(yMax - yMin) / 5 == 0.0) {
yTransform = (int) (bounds.getHeight() / 2.0);
}
int xOffset = (int) (bounds.getX() + xTransform - 1);
int yOffset = (int) (bounds.getY() + yTransform);
......
......@@ -32,18 +32,18 @@ public class SwingChart {
private static void createAndShowGUI() {
// generates sine data
int size = 100;
double[] xData1 = new double[size + 1];
double[] yData1 = new double[size + 1];
for (int i = 0; i <= size; i++) {
double radians = (Math.PI / (size / 2) * i);
xData1[i] = i - size / 2;
yData1[i] = size * Math.sin(radians);
}
// // generates sine data
// int size = 100;
// double[] xData1 = new double[size + 1];
// double[] yData1 = new double[size + 1];
// for (int i = 0; i <= size; i++) {
// double radians = (Math.PI / (size / 2) * i);
// xData1[i] = i - size / 2;
// yData1[i] = size * Math.sin(radians);
// }
// generates linear data
int size2 = 40;
int size2 = 100;
double[] xData2 = new double[size2 + 1];
double[] yData2 = new double[size2 + 1];
for (int i = 0; i <= size2; i++) {
......@@ -68,7 +68,7 @@ public class SwingChart {
// chart.setAxisTitlesVisible(false);
// Series 1
Series series1 = chart.addSeries("y=sin(x)", xData1, yData1);
// Series series1 = chart.addSeries("y=sin(x)", xData1, yData1);
// series1.setLineColor(SeriesColor.PURPLE);
// series1.setLineStyle(SeriesLineStyle.NONE);
// series1.setMarkerColor(SeriesColor.GREEN);
......
/**
* Copyright 2011 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.xcharts.example;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.xeiam.xcharts.Chart;
import com.xeiam.xcharts.JChartPanel;
import com.xeiam.xcharts.series.Series;
/**
* Demonstrated/Tests plotting horizontal and vertical lines
*
* @author timmolter
*/
public class SwingChart3 {
private static void createAndShowGUI() {
// generates linear data
double[] xData1 = new double[] { 0.0, 1.0, 2.0 };
double[] yData1 = new double[] { 0.0, 0.0, 0.0 };
double[] xData2 = new double[] { 0.0, 0.0, 0.0 };
double[] yData2 = new double[] { 0.0, 1.0, 2.0 };
// Create and set up the window.
JFrame frame = new JFrame("XChart");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);
// Create Chart
Chart chart = new Chart(800, 600);
// Customize Chart
chart.setChartTitle("Sample Chart");
chart.setXAxisTitle("X");
chart.setYAxisTitle("Y");
// chart.setChartTitleVisible(false);
// chart.setChartLegendVisible(false);
// chart.setAxisTitlesVisible(false);
// Series
Series series1 = chart.addSeries("y=0", xData1, yData1);
Series series2 = chart.addSeries("x=0", xData2, yData2);
// Swing
JPanel chartPanel = new JChartPanel(chart);
// add the panel to the content pane
frame.getContentPane().add(chartPanel, BorderLayout.CENTER);
// Display the window
frame.pack();
frame.setLocationRelativeTo(null); // centers on screen
frame.setVisible(true);
}
public static void main(String[] args) {
// Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}
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