Git Product home page Git Product logo

Comments (2)

timmolter avatar timmolter commented on July 30, 2024

Thank you for the bug report. Could you paste a working example showing the issue in code format so I can reproduce and debug? You can use this as a starting point:

public class TestForIssue834 {

  public static void main(String[] args) throws ParseException {

    XYChart chart = getXYChart();
    new SwingWrapper(chart).displayChart();
  }

  public static XYChart getXYChart() {
    XYChart chart =
        new XYChartBuilder()
            .width(720)
            .height(480)
            .title("getXYSeriesRenderStyle Example")
            .xAxisTitle("Count")
            .yAxisTitle("Value")
            .build();


    double[] xValues = new double[] {1, 2, 3};
    double[] yValues = new double[] {1, 2, 3};
    chart.addSeries("main", xValues, yValues);

    return chart;
  }
}

from xchart.

flavius-t avatar flavius-t commented on July 30, 2024

Hi there, here is a quick working example:

import org.knowm.xchart.*;

import java.text.ParseException;

public class TestForIssue834 {
    public static void main(String[] args) throws ParseException {

        XYChart chart = getXYChart();
        new SwingWrapper(chart).displayChart();
    }

    private static String customYAxisTickLabelsFormatter(Double value) {
        System.out.println("Formatting Y Axis Tick Value: " + value);
        if (value < 1e3) {
            return String.format("%.0f nJ", value);
        } else if (value < 1e6) {
            return String.format("%.2f µJ", value / 1e3);
        } else if (value < 1e9) {
            return String.format("%.2f mJ", value / 1e6);
        } else {
            return String.format("%.2f J", value / 1e9);
        }
    }

    public static XYChart getXYChart() {
        XYChart chart =
                new XYChartBuilder()
                        .width(720)
                        .height(480)
                        .title("getXYSeriesRenderStyle Example")
                        .xAxisTitle("Count")
                        .yAxisTitle("Value")
                        .build();

        // todo: uncomment this line to see the error show up in the chart
//        chart.setCustomYAxisTickLabelsFormatter(TestForIssue834::customYAxisTickLabelsFormatter);

        chart.getStyler().setYAxisLogarithmic(true);

        double[] xValues = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
        double[] yValues = new double[] {1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8};
        chart.addSeries("main", xValues, yValues);

        return chart;
    }
}

Thank you.

from xchart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.