Skip to content

Logarithmic Y-axis on Category Chart broken? #249

@Aklakan

Description

@Aklakan

The Logarithmic Line Chart works as expected and gives a chart with straight line.
However, simply substituting XYChart for CategoryChart gives a chart with the bars completely off; it seems as they are actually still linearly scaled, whereas the y axis labels are correct:

Linear scale:
xchart-categorychart-linearscale

Log scale:
xchart-categorychart-logscale

Apparently this issue exists in all version down to at least version 3.1.0.

/**
 * Logarithmic Y-Axis
 * 
 * Demonstrates the following:
 * <ul>
 * <li>Logarithmic Y-Axis
 * <li>Building a Chart with ChartBuilder
 * <li>Place legend at Inside-NW position
 */
public class CategoryChart01 {

  public static void main(String[] args) {

	CategoryChart01 exampleChart = new CategoryChart01();
	CategoryChart chart = exampleChart.getChart();
    new SwingWrapper<CategoryChart>(chart).displayChart();
  }

  public CategoryChart getChart() {

    // generates Log data
    List<Integer> xData = new ArrayList<Integer>();
    List<Double> yData = new ArrayList<Double>();
    for (int i = -3; i <= 3; i++) {
      xData.add(i);
      yData.add(Math.pow(10, i));
    }

    // Create Chart
//    XYChart chart = new XYChartBuilder().width(800).height(600).title("Powers of Ten").xAxisTitle("Power").yAxisTitle("Value").build();
    CategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("Powers of Ten").xAxisTitle("Power").yAxisTitle("Value").build();

    // Customize Chart
    chart.getStyler().setChartTitleVisible(true);
    chart.getStyler().setLegendPosition(LegendPosition.InsideNW);
    chart.getStyler().setYAxisLogarithmic(true);
    
    chart.getStyler().setYAxisMin(0.001);
    chart.getStyler().setYAxisMax(1000.0);

    // Series
    chart.addSeries("10^x", xData, yData);

    return chart;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions