2016-09-13 5 views
0

안녕하세요. 저는 AndroidPlot으로 간단한 XY 플롯을 시험해보고 있습니다. 도메인 및 범위의 라벨 색상을 변경하는 방법을 파악하는 데 문제가 있습니다. 온라인 사용 예 :AndroidPlot 도메인 및 범위 라벨의 텍스트 색상을 변경하는 방법은 무엇입니까?

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

그러나 이것은 나를 위해 컴파일되지 않습니다. 누구든지 내가 사용해야 할 것을 제안 할 수 있습니까? (또한 getGraphWidget() 대신 getGraph() 사용하여 시도했다)

또한 그래프와 도메인 레이블 사이의 여백 공간을 설정하고 그래프와 범위 레이블 사이에 공백을 설정하려고합니다. .

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; 
     } 
    }); 
+0

당신이 게시 코드를 수행 예를 들어, 그래프의 왼쪽 가장자리에 범위 라벨 용지의 상대적 위치를 조정합니다 작동 여부 두 줄에 'plot.getGraph(). getBackgroundPaint()'를 사용하여 색상을 흰색으로 설정합니다. 그래서 그것이 작동한다면, 그냥 다른 색깔로 백색을 바꾸십시오. –

+0

우리는 안드로이드에 대해 전화로 이야기하고 있습니까? 그렇다면 왜 어딘가에 콘텐츠 뷰 (XML)가 설정되지 않는 것입니까? 그것은 색을 바꿀 곳이 될 것입니다. –

답변

1

텍스트 색상 문제로는 found the answer처럼 보입니다.

그래프의 라인 라벨 인세 트로 제어되는 Androidplot 1.x 현재 그래프와 도메인/범위 라벨 사이의 간격을 조정하는 한. 프로그램

:

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

XML을 PARAM :

ap:lineLabelInsetLeft="-5dp" 
+0

정말 고마워요! :) – teiiluj

관련 문제