Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright 2015-2017 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.demo.charts.dial;

import java.util.ArrayList;

import org.knowm.xchart.DialChart;
import org.knowm.xchart.DialChartBuilder;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.demo.charts.ExampleChart;

/**
* Dial Chart
* <p>
* Demonstrates the following:
* <ul>
* <li>Dial Chart
* <li>DialChartBuilder
*/
public class DialChart01 implements ExampleChart<DialChart> {

public static void main(String[] args) {

ExampleChart<DialChart> exampleChart = new DialChart01();
ArrayList<DialChart> charts = new ArrayList<DialChart>();
{
DialChart chart = exampleChart.getChart();
chart.setTitle("Dial chart");
charts.add(chart);
}
{
DialChart chart = exampleChart.getChart();
chart.setTitle("Dial chart without green&red parts");
chart.getStyler().setRedFrom(-1);
chart.getStyler().setGreenFrom(-1);

charts.add(chart);
}
{
DialChart chart = exampleChart.getChart();
chart.setTitle("Dial chart with custom ticks&labels");
chart.getStyler().setAxisTickValues(new double[] { .33, .45, .79});
chart.getStyler().setAxisTickLabels(new String[] { "min", "average", "max"});
charts.add(chart);
}
{
DialChart chart = exampleChart.getChart();
chart.setTitle("Dial chart with custom arrow");
chart.getStyler().setArrowLengthPercentage(1.05);
chart.getStyler().setArrowArcAngle(90);
chart.getStyler().setArrowArcPercentage(.03);
charts.add(chart);
}
{
DialChart chart = exampleChart.getChart();
chart.setTitle("Full circle dial chart");
chart.getStyler().setArcAngle(360);
//chart.getStyler().setDonutThickness(1);
chart.getStyler().setAxisTickLabelsVisible(false);
charts.add(chart);
}
{
DialChart chart = exampleChart.getChart();
chart.setTitle("Full circle dial chart without donut");
chart.getStyler().setArcAngle(360);
chart.getStyler().setDonutThickness(1);
chart.getStyler().setAxisTickLabelsVisible(false);
charts.add(chart);
}
new SwingWrapper<DialChart>(charts).displayChartMatrix();
}

@Override
public DialChart getChart() {

// Create Chart
DialChart chart = new DialChartBuilder().width(480).height(400).title("Dial Chart").build();

// Series
chart.addSeries("Rate", 0.9381, "93.81 %");
chart.getStyler().setToolTipsEnabled(true);
chart.getStyler().setLegendVisible(false);

return chart;
}
}
10 changes: 0 additions & 10 deletions xchart/src/main/java/org/knowm/xchart/BubbleChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.knowm.xchart;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -244,14 +242,6 @@ private void setSeriesStyles() {

SeriesColorMarkerLineStyle seriesColorMarkerLineStyle = seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle();

/** Line Style */
BasicStroke stroke;

/** Line Color */
Color lineColor;

/** Line Width */
float lineWidth = -1.0f;
if (series.getLineStyle() == null) { // wasn't set manually
series.setLineStyle(seriesColorMarkerLineStyle.getStroke());
}
Expand Down
178 changes: 178 additions & 0 deletions xchart/src/main/java/org/knowm/xchart/DialChart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/**
* Copyright 2015-2017 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;

import java.awt.Graphics2D;

import org.knowm.xchart.internal.chartpart.Chart;
import org.knowm.xchart.internal.chartpart.Legend_Pie;
import org.knowm.xchart.internal.chartpart.Plot_Dial;
import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyle;
import org.knowm.xchart.internal.style.SeriesColorMarkerLineStyleCycler;
import org.knowm.xchart.style.DialStyler;
import org.knowm.xchart.style.Styler.ChartTheme;
import org.knowm.xchart.style.Theme;

/**
* @author timmolter
*/
public class DialChart extends Chart<DialStyler, DialSeries> {

public enum DialRenderStyle {
Polygon, Circle;
}

private DialRenderStyle radarRenderStyle = DialRenderStyle.Polygon;

/**
* Constructor - the default Chart Theme will be used (XChartTheme)
*
* @param width
* @param height
*/
public DialChart(int width, int height) {

super(width, height, new DialStyler());
plot = new Plot_Dial(this);
legend = new Legend_Pie(this);
}

/**
* Constructor
*
* @param width
* @param height
* @param theme - pass in a instance of Theme class, probably a custom Theme.
*/
public DialChart(int width, int height, Theme theme) {

this(width, height);
styler.setTheme(theme);
}

/**
* Constructor
*
* @param width
* @param height
* @param chartTheme - pass in the desired ChartTheme enum
*/
public DialChart(int width, int height, ChartTheme chartTheme) {

this(width, height, chartTheme.newInstance(chartTheme));
}

/**
* Constructor
*
* @param chartBuilder
*/
public DialChart(DialChartBuilder chartBuilder) {

this(chartBuilder.width, chartBuilder.height, chartBuilder.chartTheme);
setTitle(chartBuilder.title);
}

/**
* Add a series for a Dial type chart
*
* @param seriesName
* @param value
* @return
*/
public DialSeries addSeries(String seriesName, double value) {

return addSeries(seriesName, value, null);
}

public DialSeries addSeries(String seriesName, double value, String toolTip) {

// Sanity checks
sanityCheck(seriesName, value);

DialSeries series = new DialSeries(seriesName, value, toolTip);

seriesMap.put(seriesName, series);

return series;
}

private void sanityCheck(String seriesName, double value) {

if (seriesMap.keySet().contains(seriesName)) {
throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!");
}
if (value < 0 || value > 1) {
throw new IllegalArgumentException("Value must be in [0, 1] range!!!");
}

}

@Override
public void paint(Graphics2D g, int width, int height) {

setWidth(width);
setHeight(height);

setSeriesStyles();

paintBackground(g);

plot.paint(g);
chartTitle.paint(g);
legend.paint(g);
}

/**
* set the series color based on theme
*/
private void setSeriesStyles() {

SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(getStyler().getSeriesColors(), getStyler().getSeriesMarkers(), getStyler()
.getSeriesLines());
for (DialSeries series : getSeriesMap().values()) {

SeriesColorMarkerLineStyle seriesColorMarkerLineStyle = seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle();

if (series.getLineStyle() == null) { // wasn't set manually
series.setLineStyle(seriesColorMarkerLineStyle.getStroke());
}
if (series.getLineColor() == null) { // wasn't set manually
series.setLineColor(seriesColorMarkerLineStyle.getColor());
}
if (series.getFillColor() == null) { // wasn't set manually
series.setFillColor(seriesColorMarkerLineStyle.getColor());
}
if (series.getMarker() == null) { // wasn't set manually
series.setMarker(seriesColorMarkerLineStyle.getMarker());
}
if (series.getMarkerColor() == null) { // wasn't set manually
series.setMarkerColor(seriesColorMarkerLineStyle.getColor());
}
}
}

public DialRenderStyle getDialRenderStyle() {

return radarRenderStyle;
}

public void setDialRenderStyle(DialRenderStyle radarRenderStyle) {

this.radarRenderStyle = radarRenderStyle;
}
}
35 changes: 35 additions & 0 deletions xchart/src/main/java/org/knowm/xchart/DialChartBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2015-2017 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;

import org.knowm.xchart.internal.ChartBuilder;

/**
* @author timmolter
*/
public class DialChartBuilder extends ChartBuilder<DialChartBuilder, DialChart> {

public DialChartBuilder() {

}

@Override
public DialChart build() {

return new DialChart(this);
}
}
Loading