如何在MPAndroidChart中缩小时隐藏值标签?

时间:2017-12-19 02:37:45

标签: ios swift charts mpandroidchart ios-charts

我正在使用x y版本的import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.scene.PerspectiveCamera; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.Sphere; import javafx.stage.Stage; import javafx.util.Duration; public class PerspectiveCameraTest extends Application { @Override public void start(Stage primaryStage) { Pane pane = new Pane(); Scene scene = new Scene(pane, 800, 800, true); PerspectiveCamera camera = new PerspectiveCamera(); camera.boundsInParentProperty().addListener((obs, oldB, newB) -> System.out.println(newB)); scene.setCamera(camera); primaryStage.setScene(scene); primaryStage.show(); Sphere top = new Sphere(40); top.setMaterial(new PhongMaterial(Color.RED)); top.translateXProperty().bind(pane.widthProperty().divide(2)); top.translateYProperty().bind(Bindings.createDoubleBinding(() -> { double tanFOver2 = Math.tan(Math.toRadians(camera.getFieldOfView()/2)); return -top.getTranslateZ() * tanFOver2 ; }, top.translateZProperty(), pane.heightProperty(), camera.fieldOfViewProperty())); Sphere bottom = new Sphere(40); bottom.setMaterial(new PhongMaterial(Color.BLUE)); bottom.translateXProperty().bind(pane.widthProperty().divide(2)); bottom.translateYProperty().bind(Bindings.createDoubleBinding(() -> { double tanFOver2 = Math.tan(Math.toRadians(camera.getFieldOfView()/2)); return scene.getHeight() + bottom.getTranslateZ() * tanFOver2 ; }, bottom.translateZProperty(), pane.heightProperty(), camera.fieldOfViewProperty())); bottom.translateZProperty().bind(top.translateZProperty()); Sphere left = new Sphere(40); left.setMaterial(new PhongMaterial(Color.GREEN)); left.translateYProperty().bind(pane.heightProperty().divide(2)); left.translateXProperty().bind(Bindings.createDoubleBinding(() -> { double tanFOver2 = Math.tan(Math.toRadians(camera.getFieldOfView()/2)); return -left.getTranslateZ() * tanFOver2 * pane.getWidth() / pane.getHeight(); }, left.translateZProperty(), pane.heightProperty(), pane.widthProperty(), camera.fieldOfViewProperty())); left.translateZProperty().bind(top.translateZProperty()); Sphere right = new Sphere(40); right.setMaterial(new PhongMaterial(Color.GOLD)); right.translateYProperty().bind(pane.heightProperty().divide(2)); right.translateXProperty().bind(Bindings.createDoubleBinding(() -> { double tanFOver2 = Math.tan(Math.toRadians(camera.getFieldOfView()/2)); return pane.getWidth() + right.getTranslateZ() * tanFOver2 * pane.getWidth() / pane.getHeight() ; }, right.translateZProperty(), pane.heightProperty(), pane.widthProperty(), camera.fieldOfViewProperty())); right.translateZProperty().bind(top.translateZProperty()); TranslateTransition anim = new TranslateTransition(Duration.seconds(10), top); anim.setByZ(5000); anim.play(); pane.getChildren().addAll(top, bottom, left, right); } public static void main(String[] args) { launch(args); } } ,并试图找出当其中一些位置太靠近并且在折线图上开始重叠时如何隐藏值标签。

当缩小到某个点时隐藏所有值标签也起作用(仍然不知道如何操作),但只隐藏那些重叠的标签是最好的。

我知道我可以手动拨打Swift,但我希望在缩放时自动调用它。

enter image description here

1 个答案:

答案 0 :(得分:0)

在Android中,我使用与iOS相同的

1:找出第一和第二索引y轴标签(YAxisRenderer)之间的差异

     for (int i = from; i < to; i++)
     {

        String text = mYAxis.getFormattedLabel(i);

        double value1=Double.parseDouble(mYAxis.getFormattedLabel(1).replace(",",""));

        double value2=Double.parseDouble(mYAxis.getFormattedLabel(2).replace(",",""));


        result=(value2-value1)-40;
        //POPreferences.setDifference(String.valueOf(result));


        c.drawText(text, fixedPosition, positions[i * 2 + 1] + offset, mAxisLabelPaint);
    }

2:文本在条形图或线条上绘制时使用结果变量(BarChartRenderer.java):

  if (result >= vals[k / 2])
    {

    drawValue(c,dataSet.getValueFormatter(),vals[k / 2], entry, i, x, y,color);                                                                                          

      }