Sleepy
Sleepy

Reputation: 210

Codename One - Bar Chart

Following the doc and the example provided by cno I tried making a Bar Chart but despite the tries and the tests I always fall on the same result. I am sure I either missed something or I made a mistake somewhere, maybe there is some parameter I didn't understand well like the scale

Current BarChart Code

    public Form createBarChartForm()
    {
        XYMultipleSeriesRenderer rendererTwo
                = new XYMultipleSeriesRenderer(300);
        rendererTwo.setBarWidth(300);
        //        rendererTwo.addYTextLabel(1, "ok");
//        rendererTwo.addXTextLabel(5, "Ouuhh");

        rendererTwo.setXAxisMin(1, 50);
        rendererTwo.setXAxisMax(5, 200);
        rendererTwo.setGridColor(ColorUtil.GREEN, 10);
//        rendererTwo.setDisplayValues(true);
//        rendererTwo.setYAxisMin(5);
//        rendererTwo.setYAxisMax(5, 10);

        com.codename1.charts.models.XYMultipleSeriesDataset dataset
                = new XYMultipleSeriesDataset();

        XYSeries xYSeries =  new XYSeries("Hi", 50);
        XYSeries xYSeries2 =  new XYSeries("Hello", 150);
        XYSeries xYSeries3 =  new XYSeries("Hola", 80);

        dataset.addSeries(xYSeries);
        dataset.addSeries(xYSeries2);
        dataset.addSeries(xYSeries3);

        com.codename1.charts.views.BarChart chart = new com.codename1.charts.views.BarChart(
                dataset, rendererTwo, BarChart.Type.STACKED);
        // Wrap the chart in a Component so we can add it to a form
        ChartComponent c = new ChartComponent(chart);

        // Create a form and show it.
        Form f = new Form("Budget", new com.codename1.ui.layouts.BorderLayout());
        f.add(com.codename1.ui.layouts.BorderLayout.CENTER, c);
        return f;
    }

Result (Always The same when no errors)

Result (Stack Overflow upload would show at the bottom right and not entierly)

Upvotes: 1

Views: 213

Answers (1)

Sleepy
Sleepy

Reputation: 210

I found a chart demo on cno's website and it was more than I asked for.

Link To Charts Demo

It contains demo for all charts and it's well made.

I download the git project and tested out the one I need (extracted some methods) and it works. I would say I was 50% in the way of getting there.

I apologize if this was useless as I didn't really think the website would contain demo and I just fell on the site randomly.

Upvotes: 2

Related Questions