【问题标题】:Androidplot background, start, end values and rangesAndroidplot 背景、开始、结束值和范围
【发布时间】:2016-02-02 22:04:50
【问题描述】:

我正在尝试使用 Androidplot 创建自定义 XYPlot,但似乎无法完全配置它。

这是我的代码:

    XYSeries series = new SimpleXYSeries(Arrays.asList(dates), Arrays.asList(times), "Time on level");

    // Create a formatter to use for drawing a series using LineAndPointRenderer:
    LineAndPointFormatter formatter = new LineAndPointFormatter(Color.rgb(0, 100, 0), Color.rgb(0, 100, 0), null, new PointLabelFormatter(Color.BLUE));
    totalTimePlot.setRangeValueFormat(new DecimalFormat("#.#"));

    totalTimePlot.setGridPadding(0, 0, 0, 200);
    totalTimePlot.setBackgroundColor(Color.WHITE);
    totalTimePlot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    totalTimePlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    totalTimePlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    totalTimePlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    totalTimePlot.setTicksPerDomainLabel(1);
    totalTimePlot.setRangeStepValue(10);
    totalTimePlot.getGraphWidget().setDomainLabelOrientation(-90);
    totalTimePlot.setMarkupEnabled(false);
    totalTimePlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);

    totalTimePlot.setDomainValueFormat(new Format() {
        SimpleDateFormat sdf = new SimpleDateFormat("EEE(MM.dd)-HH:mm:ss");

        @Override
        public StringBuffer format(Object object, StringBuffer buffer, FieldPosition field) {
            long timestamp = ((Number) object).longValue();
            Date date = new Date(timestamp);
            return sdf.format(date, buffer, field);
        }

        @Override
        public Object parseObject(String string, ParsePosition position) {
            return null;
        }
    });

    totalTimePlot.getGraphWidget().setPaddingLeft(4);
    totalTimePlot.addSeries(series, formatter);

这是最终结果:

如您所见,这非常难看。你能帮我至少配置一下,以便显示范围标签。我还想知道如何使背景变白以及第一个和最后一个“刻度”可见。

谢谢。

编辑:

我设法通过设置边界来包含第一个和最后一个值。但其他问题仍然存在。

【问题讨论】:

    标签: android androidplot


    【解决方案1】:

    同意这很丑:-) 如果您列出一些您想改进的具体项目,那么给您建议会更容易。话虽如此,我将从以下几点开始:

    • 使用DemoApp's SimpleXYPlotActivity xml style 作为起点。这应该可以解决您的边距问题并改善整体外观。
    • 简化域标签的日期/时间格式。也许像日/月小时:分钟。我不知道您的确切用例,所以您可能需要您使用的格式。
    • 摆脱构成情节的深色背景。
    • 考虑使用CatmullRomInterpolator 绘制平滑线。

    【讨论】:

      猜你喜欢
      • 2013-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 2011-05-29
      • 1970-01-01
      相关资源
      最近更新 更多