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

Issue #139 bug Fix - stick chart - how to increase the distance between the sticks

parent a9d5d13e
No related branches found
No related tags found
No related merge requests found
/**
* Copyright 2015-2016 Knowm Inc. (http://knowm.org) and contributors.
* Copyright 2011-2015 Xeiam LLC (http://xeiam.com) and contributors.
*
* 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 org.knowm.xchart.standalone;
import org.knowm.xchart.ChartBuilder_Category;
import org.knowm.xchart.Chart_Category;
import org.knowm.xchart.Series_Category.ChartCategorySeriesRenderStyle;
import org.knowm.xchart.SwingWrapper;
/**
* @author timmolter
*/
public class TestForIssue139 {
public static void main(String[] args) {
int[] x = new int[] { 0, 1, 2, 3, 4 };
int[] a = new int[] { 1, 3, 1, 2, 1 };
int[] b = new int[] { 2, 1, 1, 2, 2 };
int[] c = new int[] { 1, 1, 2, 3, 3 };
Chart_Category chart = new ChartBuilder_Category().width(640).height(480).build();
chart.getStyler().setLegendVisible(false);
chart.getStyler().setDefaultSeriesRenderStyle(ChartCategorySeriesRenderStyle.Stick);
// chart.getStyler().setBarsOverlapped(true);
chart.getStyler().setBarWidthPercentage(.25);
chart.addSeries("A", x, a);
chart.addSeries("B", x, b);
chart.addSeries("C", x, c);
new SwingWrapper(chart).displayChart();
}
}
......@@ -173,23 +173,13 @@ public class PlotContent_Category_Bar<ST extends Styler, S extends Series> exten
double barWidthPercentage = stylerCategory.getBarWidthPercentage();
barWidth = gridStep * barWidthPercentage;
double barMargin = gridStep * (1 - barWidthPercentage) / 2;
if (ChartCategorySeriesRenderStyle.Stick.equals(series.getChartCategorySeriesRenderStyle())) {
xOffset = bounds.getX() + xLeftMargin + categoryCounter++ * gridStep + gridStep / 2;
}
else {
xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + barMargin;
}
xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + barMargin;
}
else {
double barWidthPercentage = stylerCategory.getBarWidthPercentage();
barWidth = gridStep / chart.getSeriesMap().size() * barWidthPercentage;
double barMargin = gridStep * (1 - barWidthPercentage) / 2;
if (ChartCategorySeriesRenderStyle.Stick.equals(series.getChartCategorySeriesRenderStyle())) {
xOffset = bounds.getX() + xLeftMargin + categoryCounter++ * gridStep + seriesCounter * barMargin + gridStep / chart.getSeriesMap().size() / 2;
}
else {
xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + seriesCounter * barWidth + barMargin;
}
xOffset = bounds.getX() + xLeftMargin + gridStep * categoryCounter++ + seriesCounter * barWidth + barMargin;
}
// paint series
......@@ -216,19 +206,21 @@ public class PlotContent_Category_Bar<ST extends Styler, S extends Series> exten
g.setColor(series.getLineColor());
g.setStroke(series.getLineStyle());
Shape line = new Line2D.Double(xOffset, zeroOffset, xOffset, yOffset);
Shape line = new Line2D.Double(xOffset + barWidth / 2, zeroOffset, xOffset + barWidth / 2, yOffset);
g.draw(line);
}
// paint marker
if (series.getMarker() != null) {
// if (series.getMarker() != null) {
if (stylerCategory.shouldShowMarkers() && series.getMarker() != null) { // if set to Marker.NONE,
// the
g.setColor(series.getMarkerColor());
if (y <= 0) {
series.getMarker().paint(g, xOffset, zeroOffset, stylerCategory.getMarkerSize());
series.getMarker().paint(g, xOffset + barWidth / 2, zeroOffset, stylerCategory.getMarkerSize());
}
else {
series.getMarker().paint(g, xOffset, yOffset, stylerCategory.getMarkerSize());
series.getMarker().paint(g, xOffset + barWidth / 2, yOffset, stylerCategory.getMarkerSize());
}
}
}
......
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