如何在cn1中制作折线图

罗布林

我想制作一个折线图,但是我几乎不知道如何使用图表API。我已经调整了制作饼图的代码,以尝试制作折线图。如果有实现方面的帮助,或者有关于如何制作折线图的教程,我将不胜感激。

    package userclasses;

import com.codename1.charts.ChartComponent;
import com.codename1.charts.models.XYMultipleSeriesDataset;
import com.codename1.charts.models.XYSeries;
import com.codename1.charts.renderers.XYMultipleSeriesRenderer;
import com.codename1.charts.util.ColorUtil;
import com.codename1.charts.views.LineChart;
import com.codename1.ui.Form;
import com.codename1.ui.layouts.BorderLayout;

/**
 *
 * @author Robin
 */
public class LineGraph1 {
    private XYMultipleSeriesRenderer buildXYMSRenderer(int[] colors) {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        renderer.setLabelsTextSize(15);
        renderer.setLegendTextSize(15);
        renderer.setMargins(new int[]{20, 30, 15, 0});

        return renderer;
    }

    protected XYMultipleSeriesDataset buildXYMultipleSeriesDataSeries(String title, double[] xValues, double[] yValues) {
        XYMultipleSeriesDataset series = new XYMultipleSeriesDataset();
        int k = 0;
        XYSeries xys = new XYSeries(title);
        for (int i = 0; i < xValues.length; i++) {
            xys.add(xValues[i], yValues[i]);
        }
 {

        }
        series.addSeries(xys);

        return series ;
    }

    public Form createLineChartForm() {

        // Generate the values
        double[] xValues = new double[]{1, 2, 3, 4, 5};
        double[] yValues = new double[]{20,26,31,21,44};


        // Set up the renderer
        int[] colors = new int[]{ColorUtil.BLUE, ColorUtil.GREEN, ColorUtil.MAGENTA, ColorUtil.YELLOW, ColorUtil.CYAN};
        XYMultipleSeriesRenderer renderer = buildXYMSRenderer(colors);
        renderer.setZoomButtonsVisible(true);
        renderer.setZoomEnabled(true);
        renderer.setChartTitleTextSize(20);
        renderer.setDisplayValues(true);
        renderer.setShowLabels(true);
        //SimpleSeriesRenderer r = renderer.getSeriesRendererAt(0);

        // Create the chart ... pass the values and renderer to the chart object.


        LineChart chart = new LineChart(buildXYMultipleSeriesDataSeries("Project budget", xValues, yValues), renderer);
        //LineChart chart2 = new LineChart(buildXYMultipleSeriesDataSeries("Project budget", values), new XYMultipleSeriesRenderer());
        // 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("Graph");
        f.setLayout(new BorderLayout());
        f.addComponent(BorderLayout.CENTER, c);
        return f;
    }
}
Shai Almog

我同意图表包是相当低的水平。我们可能想提供一些“用户友好”的东西。

我建议在略有简化的新图表演示中使用折线图演示代码:https : //www.codenameone.com/blog/charts-demo-revisited.html

此处查看产生此折线图的代码

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在cn1中制作折线图

来自分类Dev

如何在谷歌折线图中制作虚线

来自分类Dev

如何在较旧版本的Excel中测试在Excel 2016中制作的折线图

来自分类Dev

如何制作垂直折线图?

来自分类Dev

如何在Oxyplot中显示折线图的绘图点?

来自分类Dev

如何在Java Swing中绘制折线图

来自分类Dev

如何在Flutter中创建步骤折线图

来自分类Dev

如何在python中绘制“多线”折线图?

来自分类Dev

如何在Jupyter中更正折线图起点?

来自分类Dev

如何在Jupyter中更正折线图起点?

来自分类Dev

如何在Swift中绘制折线图?

来自分类Dev

我如何在python中绘制折线图?

来自分类Dev

如何在ChartJS中销毁折线图

来自分类Dev

如何在d3中的每行中制作带有虚线段的多折线图

来自分类Dev

制作简单的折线图

来自分类Dev

如何在 CN1 中创建此用户界面?

来自分类Dev

我如何在R中的折线图中做一个折线或空白

来自分类Dev

如何在Excel中的多个折线图中仅查看一条折线

来自分类Dev

如何使用R中的多个变量制作具有多条线的折线图

来自分类Dev

如何通过迭代python中的pandas列制作折线图?

来自分类Dev

如何使用 Plots.jl 在 Julia 中制作堆积面积/折线图?

来自分类Dev

如何通过Shiny制作交互式折线图?

来自分类Dev

如何使用SVG和XSL制作折线图

来自分类Dev

在Excel中制作多个单独的折线图

来自分类Dev

如何平滑折线图?

来自分类Dev

如何平滑折线图?

来自分类Dev

如何平滑折线图?

来自分类Dev

matplotlib中的折线图

来自分类Dev

Visual Basic-制作折线图