1

I am struggling to move legend widget in androidplot to the place where I want.

I am trying to use androidplot to render a set of data. I followed the way of placing legend widget to a point by calling position() method used in DemoApp. But I never succeeded. I was blocked by this for almost 1 week. Can someone help me check whether i made some mistakes in my code. I did not find any documentation about how to use this lib except the sample code.

My layout xml:

<com.androidplot.xy.XYPlot
    android:id="@+id/mySimpleXYPlot"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_below="@+id/seperator1"
    androidPlot.domainLabelWidget.labelPaint.textSize="@dimen/domain_label_font_size"
  androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
        androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"
        androidPlot.graphWidget.rangeLabelPaint.textSize="@dimen/range_tick_label_font_size"
        androidPlot.graphWidget.rangeOriginLabelPaint.textSize="@dimen/range_tick_label_font_size"
        androidPlot.legendWidget.heightMetric.value="25dp"
        androidPlot.graphWidget.marginBottom="25dp"
        androidPlot.graphWidget.marginLeft="15dp"
        androidPlot.graphWidget.marginRight="10dp"
        androidPlot.graphWidget.marginTop="20dp"
        androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"
        androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"
        androidPlot.legendWidget.positionMetrics.anchor="left_top"
        androidPlot.legendWidget.positionMetrics.xPositionMetric.value="0"
        androidPlot.legendWidget.textPaint.textSize="@dimen/legend_text_font_size"
        androidPlot.legendWidget.widthMetric.value="100dp"
        androidPlot.rangeLabelWidget.labelPaint.textSize="@dimen/range_label_font_size"
        androidPlot.titleWidget.labelPaint.textSize="@dimen/title_font_size" />
    <!-- androidPlot.graphWidget.gridLinePaint.color="#000000"/> -->

My source code:

 private void makePlotPretty() {
            // use a 2x2 grid with room for 4 items:
            plot.getLegendWidget().setTableModel(new DynamicTableModel(2, 2));

            // add a semi-transparent black background to the legend
            // so it's easier to see overlaid on top of our plot:
            Paint bgPaint = new Paint();
            bgPaint.setColor(Color.BLACK);
            bgPaint.setStyle(Paint.Style.FILL);
            bgPaint.setAlpha(255);

            plot.getLegendWidget().setBackgroundPaint(bgPaint);

/*          plot.getLegendWidget().setPositionMetrics(null);
*/

            plot.getLegendWidget().setWidth(PixelUtils.dpToPix(40), SizeLayoutType.FILL);

            plot.getGraphWidget().setRangeLabelHorizontalOffset(-1);

            plot.getLegendWidget().position(125, XLayoutStyle.ABSOLUTE_FROM_LEFT, 100, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.LEFT_TOP);

        }
4

1 回答 1

1

有一个文档,包括一个带有示例代码的图例页面,包括定位图例。

临界线看起来是

       mySimpleXYPlot.position(
            mySimpleXYPlot.getLegendWidget(),
            20,
            XLayoutStyle.ABSOLUTE_FROM_RIGHT,
            35,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM,
            AnchorPosition.RIGHT_BOTTOM);
于 2013-12-31T16:40:45.603 回答