如何更改文本颜色为 AndroidPlot 域和范围标签?

标签: Android
发布时间: 2016/9/28 0:42:50
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

嗨所有我只试着简单 XY 阴谋集团与 AndroidPlot。我有问题弄清楚如何更改标签颜色域和范围。网上的例子说,使用︰

plot.getGraphWidget().getDomainLabelPaint().setColor(my_colour) plot.getDomainLabelWidget().getLabelPaint().setColor(my_colour)

然而,这并没有编制对我来说。任何人都可以提出我需要使用吗?(我自己也尝试使用 getGraph() 而不 getGraphWidget())

我也想设置边距 space 之间的图和域的标签,并且 space 之间图和范围的标签,如果任何人为此提出了一个建议。

    plot = (XYPlot) findViewById(R.id.plot);
    plot.setPlotMargins(0, 0, 0, 0);
    plot.getBackgroundPaint().setColor(Color.WHITE);
    plot.setBorderStyle(XYPlot.BorderStyle.NONE, null, null);
    plot.getGraph().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraph().getGridBackgroundPaint().setColor(Color.WHITE);
    plot.getGraph().getDomainOriginLinePaint().setColor(Color.TRANSPARENT);
    plot.getGraph().getRangeOriginLinePaint().setColor(Color.TRANSPARENT);


    // create a couple arrays of y-values to plot:
    final Number[] domainLabels = {1, 10, 20, 6, 7, 8, 9, 10, 13, 14};
    Number[] series1Numbers = {1, 4, 2, 8, 4, 16, 8, 32, 16, 64};

    // turn the above arrays into XYSeries':
    // (Y_VALS_ONLY means use the element index as the x value)
    XYSeries series1 = new SimpleXYSeries(
            Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");


    // create formatters to use for drawing a series using LineAndPointRenderer
    // and configure them from xml:
    LineAndPointFormatter series1Format = new LineAndPointFormatter();
    series1Format.setPointLabelFormatter(new PointLabelFormatter());
    series1Format.configure(getApplicationContext(),
            R.xml.line_point_formatter_with_labels);

    LineAndPointFormatter series2Format = new LineAndPointFormatter();
    series2Format.setPointLabelFormatter(new PointLabelFormatter());
    series2Format.configure(getApplicationContext(),
            R.xml.line_point_formatter_with_labels_2);

    // add an "dash" effect to the series2 line:
    series2Format.getLinePaint().setPathEffect(
            new DashPathEffect(new float[]{

                    // always use DP when specifying pixel sizes, to keep things consistent across devices:
                    PixelUtils.dpToPix(20),
                    PixelUtils.dpToPix(15)}, 0));

    plot.addSeries(series1, series1Format);
    plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).setFormat(new Format() {
        @Override
        public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
            int i = Math.round(((Number) obj).floatValue());
            return toAppendTo.append(domainLabels[i]);
        }

        @Override
        public Object parseObject(String source, ParsePosition pos) {
            return null;
        }
    });

解决方法 1:

看起来像你找到了答案对您的文本 color 问题。

在调整你的图表和域之间的间距 / 范围标签,如 Androidplot 由图线标签插入控制的 1.x。 例如,若要调整范围标签图形的左边缘的相对定位︰

以编程方式︰

// move line labels away from the graph by 5dp:
plot.getGraph().getLineLabelInsets().setLeft(PixelUtils.dpToPix(-5));

xml参数︰

ap:lineLabelInsetLeft="-5dp"
官方微信
官方QQ群
31647020