我使用 MPAndriodChart,我想将多个 ScatterDataSet 与一个 LineDataSet 组合在一起
CombinedChart chart = (CombinedChart) findViewById(R.id.chart);
CombinedData chartData = new CombinedData();
ScatterData scatterData = data.getScatterData();
chartData.setData(scatterData);
chartData.setData(data.getLineData());
chart.setData(chartData);
chart.invalidate();
Run Code Online (Sandbox Code Playgroud)
该线工作正常,但在 ScatterData 上我得到一个 NegativeArraySizeException:
java.lang.NegativeArraySizeException: -10
at com.github.mikephil.charting.utils.Transformer.generateTransformedValuesScatter(Transformer.java:110)
at com.github.mikephil.charting.renderer.ScatterChartRenderer.drawValues(ScatterChartRenderer.java:106)
at com.github.mikephil.charting.renderer.CombinedChartRenderer.drawValues(CombinedChartRenderer.java:95)
Run Code Online (Sandbox Code Playgroud)
我传递的似乎是完全有效的数据:
[Entry, x: 5.5699 y (sum): -0.5020655, Entry, x: 4.2394395 y (sum): 0.21312527, Entry, x: 3.5619884 y (sum): 0.45908606, Entry, x: 0.64683366 y (sum): 0.13041855, Entry, x: 5.2063227 y (sum): -0.3853986, Entry, x: 4.3252435 y (sum): -0.31767017, Entry, x: 5.9881873 y (sum): 0.2213649, Entry, …Run Code Online (Sandbox Code Playgroud) 我已经弄清楚如何使用下面的方法将 X 轴值设置为显示在底部而不是顶部。我现在遇到的问题是,我的 Y 轴值同时显示在左侧和右侧,而我只希望它们显示在图表的左侧。
if (response.isSuccessful()) {
// Reload data source
Items = new ArrayList<>();
Items.clear();
Items.addAll(response.body());
//currentReportingGroup = Items.get(0).ReportingGroup;
//ItemsAdapter.notifyDataSetChanged();
Log.i(TAG, "onResponse: ");
//load(view);
BarChart chart = (BarChart) aq.id(R.id.chart).getView();
XAxis xAxisChart = chart.getXAxis();
YAxis yAxisChart = chart.getAxisLeft();
//yAxisChart.setValueFormatter(new MyAxisValueFormatter());
// yAxisChart.setPosition(YAxis.YAxisLabelPosition.);
xAxisChart.setPosition(XAxis.XAxisPosition.BOTTOM);
BarData data = new BarData(getXAxisValues(), getDataSet());
chart.setData(data);
chart.setDescription("");
chart.animateXY(2000, 2000);
chart.invalidate();
}
Run Code Online (Sandbox Code Playgroud) Initially the graph goes from -10 to 10 but i want that when the user scrolls right the values are evaluated and the graph "grows". Is there any listeners for that. I meant that when the user scrolls to the right then i add more points as for function, there is always a value of y for an x. The graph keep constructing itself when the user scrolls up down right or left.
我正在使用MPAndroidChart条形图库,其中,我曾经chart.setDrawValueAboveBar(false)在条形内部设置条形值,现在我想在条形内部垂直显示值。
请帮忙..提前谢谢你。
我现在使用 MPAndroidChart v3.0.2。问题是最后一个数据('05?')没有显示......
这是我进入 Debug xVals 时的值:1?, 2?, 5?
它是来源和结果截图。
我认为“5?” 进入'红圈'...但我不知道原因..
LineChart chart = (LineChart) findViewById(R.id.chart);
if (ExRegList.length() == 0) {
chart.clear();
chart.setDescription(null);
chart.setNoDataText("???? ???? ????."); // There is no data.
chart.invalidate();
} else {
ArrayList<Entry> entries = new ArrayList<Entry>();
final String[] xVals = new String[ExRegList.length()];
try {
for (int i = 0; i < ExRegList.length(); i++) {
JSONObject obj = ExRegList.getJSONObject(i);
String date = obj.getString("REG_DT").split("-")[2] + "?";
xVals[i] = date;
int score = obj.getInt("ANSWER02");
switch (score) {
case …Run Code Online (Sandbox Code Playgroud) 我想通过MPAndroidChart:v3.0.3这样创建图表,以便我将它的 lib 实现到我的 gradle 中。在我的 MainActivity 类中初始化图表后进行练习,如下所示:
barChart = findViewById(R.id.chart_report);
barChart.setDrawBarShadow(false);
barChart.setDrawValueAboveBar(true);
barChart.setPinchZoom(false);
barChart.setDrawGridBackground(true);
barChart.setFitBars(true);
Run Code Online (Sandbox Code Playgroud)
我有这样设置图表:
ArrayList<BarEntry> barEntries = new ArrayList<>();
barEntries.add(new BarEntry(1, 40f));
barEntries.add(new BarEntry(2, 20f));
barEntries.add(new BarEntry(3, 35f));
barEntries.add(new BarEntry(4, 15f));
BarDataSet barDataSet = new BarDataSet(barEntries, "DataSet1");
barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
BarData data = new BarData(barDataSet);
data.setBarWidth(0.3f);
barChart.setData(data);
Run Code Online (Sandbox Code Playgroud)
现在一切正常,但我想改变它XAxis,以便我创建一个类并实现 IAxisValueFormatter 接口,如下所示:
public class ChartAXisValueFormatter implements IAxisValueFormatter {
private String[] mValues;
public ChartAXisValueFormatter(String[] values) {
mValues = values;
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
int …Run Code Online (Sandbox Code Playgroud) 我正在使用 Android MP Chart lib 来绘制很棒的图表。
我试图突出显示图表上的值,但它没有将突出显示放在正确的位置,或者抛出ArrayIndexOutOfBoundsException。
我为它做了一个小虚拟项目。当用户单击下一个按钮时,突出显示应向正方向移动。
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
final int DATA_MAX_COUNT = 30;
List<MyData> list = new ArrayList<>(); ///<Dummy data stored in here
List<Entry> entries = new ArrayList<>(); ///<Entries for MP Chart
int highlightIndex = 0; ///<Chart's data index to be highlighted
CombinedChart combinedChart; ///<I use combined chart because there will be more data sets added later on
Button prevBtn; ///<Button for highlight control
Button nextBtn; ///<Button …Run Code Online (Sandbox Code Playgroud) 我正在使用mpandroidchart库来创建饼图。
我想格式化饼图上的文本标签,但我不知道该怎么做。我试过用
data.setValueTextColor(ContextCompat.getColor(getActivity(),R.color.black));
Run Code Online (Sandbox Code Playgroud)
但是,它只更改数据的值,而不是标签。另外,我想成为饼图中的标签,我也尝试过使用以下代码,
PieEntry entry2=new PieEntry(50-scratches,"Remaining \nScratches");
Run Code Online (Sandbox Code Playgroud)
但是,它没有用。
我的代码如下:
private void setPiechart(float scratches) {
List<PieEntry> values = new ArrayList<>();
PieEntry entry1=new PieEntry(scratches,"Scratches");
PieEntry entry2=new PieEntry(50-scratches,"Remaining \nScratches");
values.add(entry1);
values.add(entry2);
PieDataSet dataSet = new PieDataSet(values,"");
dataSet.setColors(ContextCompat.getColor(getActivity(),R.color.color_veridoc_gradient1),
ContextCompat.getColor(getActivity(),R.color.colorBgChat));
dataSet.setHighlightEnabled(true);
dataSet.setAutomaticallyDisableSliceSpacing(true);
dataSet.setSliceSpace(10);
PieData data=new PieData(dataSet);
data.setValueTextSize(20f);
data.setValueTextColor(ContextCompat.getColor(getActivity(),R.color.black));
pieChart.setData(data);
Description description=new Description();
description.setText("Scratches ");
pieChart.setDescription(description);
pieChart.setDrawHoleEnabled(true);
pieChart.setHoleRadius(10f);
pieChart.animateY(500);
Legend legend = pieChart.getLegend();
legend.setEnabled(true);
legend.setTextColor(Color.BLACK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
pieChart.setElevation(10);
}
}
Run Code Online (Sandbox Code Playgroud)
我想做的是简而言之
- 更改饼图中的标签颜色(从白色到黑色)
- 防止标签超出饼图。(例如,如图所示的剩余划痕)
有人可以帮我吗?
我还尝试了以下链接中提到的这些解决方案。
我正在使用的代码是这个
private fun setData() {
val entries: MutableList<Entry> = ArrayList()
entries.add(Entry(0f, 4f))
entries.add(Entry(1f, 3f))
entries.add(Entry(2f, 2f))
entries.add(Entry(3f, 1f))
entries.add(Entry(4f, 5f))
entries.add(Entry(5f, 4f))
entries.add(Entry(6f, 6f))
val dataSet = LineDataSet(entries, "Customized values")
dataSet.color = ContextCompat.getColor(context!!, R.color.colorPrimary)
dataSet.valueTextColor = ContextCompat.getColor(context!!, R.color.colorPrimaryDark)
//****
// Controlling X axis
val xAxis = line_chart.xAxis
// Set the xAxis position to bottom. Default is top
xAxis.position = XAxis.XAxisPosition.BOTTOM
//Customizing x axis value
val months = arrayOf("M", "T", "W", "T", "F", "S", …Run Code Online (Sandbox Code Playgroud)