首页 > 解决方案 > 如何自定义 XYPlot 属性 - 添加 X 和 Y 轴标签并更改图例文本大小?

问题描述

我尝试了什么:我正在为我的动态图使用 XYPlot,它运行良好。我试图在我的initplot()函数中自定义它。我尝试使用getLegendWidget(),getDomainLabelWidget()getRangeLabelWidget()函数(如下所示)。

我在找什么:但我不确定,

  1. 如何添加 X 和 Y 轴标签,如下图所示。
  2. 如何增加图例项的文本大小

我要使用哪个参数?我的尝试如下图所示。我真的很感激对此的任何建议。

-谢谢-

在此处输入图像描述

情节.xml:

   <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <com.androidplot.xy.XYPlot
            android:id="@+id/dynamicPlot"
            title="Data Plot"
            android:layout_width="wrap_content"
            android:layout_height="530dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:background="#FFFFFF" />
    </FrameLayout>

初始化图():

private void initPlot() {
        plot = (XYPlot) getView().findViewById(R.id.dynamicPlot);

    //..LPF formatting here 

        plot.getLegendWidget().setTableModel(new DynamicTableModel(1,3));
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y;
        plot.getLegendWidget().setSize(new SizeMetrics(width/3, SizeLayoutType.ABSOLUTE, height/4, SizeLayoutType.ABSOLUTE));

    //..domain/range color formatting here 

        plot.getGraphWidget().getDomainLabelPaint().setTextSize(40);
        plot.getDomainLabelWidget().pack();
        outlinePaint = plot.getGraphWidget().getDomainOriginLinePaint();
        outlinePaint.setStrokeWidth(3);
        plot.getGraphWidget().setClippingEnabled(false);
        plot.getGraphWidget().getRangeLabelPaint().setTextSize(30);
        plot.getRangeLabelWidget().pack();
        outlinePaint = plot.getGraphWidget().getRangeOriginLinePaint();
        outlinePaint.setStrokeWidth(3);
        //plot.getLayoutManager().remove(plot.getRangeLabelWidget());
        //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
        plot.getDomainLabelWidget().setVisible(true);
    }

标签: javaandroidlinegraphandroidplot

解决方案


推荐阅读