{"record":{"id":"de798415980700ae","repo":"PhilJay/MPAndroidChart","slug":"piechart-has-no-xaxis","errorCode":null,"errorMessage":"PieChart has no XAxis","messagePattern":"PieChart has no XAxis","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java","lineNumber":341,"sourceCode":"     * calculates the needed angle for a given value\n     *\n     * @param value\n     * @param yValueSum\n     * @return\n     */\n    private float calcAngle(float value, float yValueSum) {\n        return value / yValueSum * mMaxAngle;\n    }\n\n    /**\n     * This will throw an exception, PieChart has no XAxis object.\n     *\n     * @return\n     */\n    @Deprecated\n    @Override\n    public XAxis getXAxis() {\n        throw new RuntimeException(\"PieChart has no XAxis\");\n    }\n\n    @Override\n    public int getIndexForAngle(float angle) {\n\n        // take the current angle of the chart into consideration\n        float a = Utils.getNormalizedAngle(angle - getRotationAngle());\n\n        for (int i = 0; i < mAbsoluteAngles.length; i++) {\n            if (mAbsoluteAngles[i] > a)\n                return i;\n        }\n\n        return -1; // return -1 if no index found\n    }\n\n    /**\n     * Returns the index of the DataSet this x-index belongs to.","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/PhilJay/MPAndroidChart/blob/9c7275a0596a7ac0e50ca566e680f7f9d73607af/MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java#L323-L359","documentation":"PieChart.getXAxis() always throws a RuntimeException because a pie chart has no XAxis concept (slices are arranged by angle, not by an x-axis). The method is kept only for API compatibility with the Chart base class and is annotated @Deprecated to signal it should never be used. Calling it directly, or via reflection/generic code that treats every chart through the base API, triggers the crash.","triggerScenarios":"Calling pieChart.getXAxis() directly to set labels/position. Generic helper code that loops over Chart instances and calls getXAxis().setEnabled(...). Migration of a BarChart/LineChart to PieChart without removing XAxis configuration calls. Using a third-party theming library that touches XAxis on all charts.","commonSituations":"Converting an existing bar/line chart screen to a pie chart and leaving axis styling code; copy-pasting chart-setup code across chart types; static-analysis or theming code that assumes all Chart subclasses expose an XAxis.","solutions":["Remove all getXAxis() calls for PieChart instances; pie charts do not support an x-axis.","Type-narrow before configuring axes: if (!(chart instanceof PieChart)) chart.getXAxis()... .","Configure pie-specific styling via pieChart.getXAxis() replacement APIs (e.g. setEntryLabelColor, setDrawEntryLabels, setUsePercentValues).","Search the codebase for getXAxis() and confirm none are reached by PieChart instances."],"exampleFix":"// before\nchart.getXAxis().setEnabled(false); // crashes if chart is a PieChart\n\n// after\nif (!(chart instanceof PieChart)) {\n    chart.getXAxis().setEnabled(false);\n}","handlingStrategy":"type-guard","validationCode":"if (!(chart instanceof PieChart)) {\n    chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);\n}","typeGuard":"boolean hasXAxis(Chart<?, ?> chart) {\n    return !(chart instanceof PieChart);\n}","tryCatchPattern":null,"preventionTips":["Never call getXAxis() on a PieChart; the method is @Deprecated.","Centralize axis styling behind a helper that type-checks for PieChart.","When migrating chart types, grep for getXAxis() in the affected screen."],"tags":["pie-chart","xaxis","deprecated","api-misuse"],"backgroundTag":null,"analyzedSha":"9c7275a0596a7ac0e50ca566e680f7f9d73607af","analyzedAt":"2026-08-14T00:17:56.136Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}