有谁知道,如何重置MPAndroid图表中的选定项目 - PieChart?我需要能够点击一个项目,例如"十万"次,但每次它都给我onNothingSelected()事件而不是onValueSelected()
我只需要调用onValueSelected()事件.
有人可以帮忙吗?
谢谢
使用MPAndroidChart,有没有办法在折线图中仅绘制一个圆圈?这意味着只有线的末端将表示为圆形,如下图所示:

@PhilJay
我正在尝试将轴标题添加到使用mpandroid图表库创建的条形图中.我在我的活动中使用了多个片段,条形图是一个片段.我正在动态添加数据,一切正常.我想在x和y轴上添加标题,当我搜索时,我发现它不受库支持.他们建议我们在图表中添加textview或编辑库.
我知道这个问题与这篇文章相同,但他们没有答案. 如何将字符串标签添加到MPAndroidCharts
我尝试添加textview进行查看,并将其添加到图表的顶部.我尝试过给layout_gravity,但它没有用.如何将textview添加到视图的底部.我也需要添加y轴标题.我尝试添加到容器和视图.
public class BarChartFragment extends Fragment {
ScreenUtility screenUtility;
BarChart bar;
String nameOfChart,xAxisDesciption,yAxisDescription;
TextView xAxisName;
public BarChartFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
//this.setRetainInstance(true);
super.onCreate(savedInstanceState);
if (getArguments() != null) {
}
}
public View getView(){
return bar.getRootView();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
screenUtility = new ScreenUtility(getActivity());
ArrayList<BarEntry> entries = new ArrayList<>();
BarDataSet dataSet = new BarDataSet(entries,nameOfChart);
dataSet.setColors(getColors());
dataSet.setStackLabels(new String[]{"CU1", "CU2"});
dataSet.setValueFormatter(new MyValueFormatter());
ArrayList<String> labels …Run Code Online (Sandbox Code Playgroud) 我使用Android-MPChartLibrary来显示LineChart.空视图LineChart显示"无图表数据可用"和"无数据显示"
chart.setDescription("");
chart.setNoDataTextDescription("No data to display");
Run Code Online (Sandbox Code Playgroud)
我只是想说"没有要显示的数据",但不确定它为何显示两者.
我已经下载了MPAndroidChart库来绘制LineChart,我注意到这个LineChart总是在yAxis上绘制xAxis,我需要在yAxis的底部绘制xAxis
这是我初始化图表的方式
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setDescription("");
mChart.setNoDataTextDescription("You need to provide data for the chart.");
// enable value highlighting
mChart.setHighlightEnabled(true);
// enable touch gestures
mChart.setTouchEnabled(true);
mChart.setDragDecelerationFrictionCoef(0.9f);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);
mChart.setHighlightPerDragEnabled(true);
mChart.setBackgroundColor(Color.WHITE);
XAxis xAxis = mChart.getXAxis();
xAxis.setDrawGridLines(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setAxisMaxValue(200f);
leftAxis.setDrawGridLines(false);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawAxisLine(false);
rightAxis.setTextColor(Color.WHITE);
rightAxis.setDrawGridLines(false);
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
// set the marker to the chart
mChart.setMarkerView(mv);
Run Code Online (Sandbox Code Playgroud) 我需要在饼图中为每个切片定义特定的十六进制值.
我正在关注维基,但该方法似乎并不适用PieDataSet
PieDataSet dataSet = new PieDataSet(entries, "Fuel");
dataSet.setColors(new int[] { R.color.green1, R.color.green2, R.color.green3, R.color.green4 }, Context);
Run Code Online (Sandbox Code Playgroud)
显示以下错误:
Cannot resolve symbol 'green1'
Expression expected <-- At the 'Context'
Run Code Online (Sandbox Code Playgroud)
是否有另一种设置饼图切片颜色的方法?这似乎适用于折线图,但不适用于饼图.
我正在使用MPAndroidChart在折线图中显示我的数据。对于每个日期,我都有自己的价值。
这样很好。我现在想做的是不绘制0值,而是绘制2个相邻的非零值(如趋势线)之间的线,同时继续在x轴上显示零值的日期。
我该如何实现这种行为?
我开始使用MPAndroidChart库来构建一个StackedBarChart显示三个y值.这是代码:
public class Plot
{
final Context context;
final BarData data;
private int count;
public StackedBarPlot(Context context)
{
this.context = context;
data = setData();
}
protected BarData setData()
{
final List<BarEntry> entries = new ArrayList<>();
for (DatabaseEntry entry : entryList)
{
final float total = (float) entry.getTotal();
final float[] y = {100 * entry.getN1() / total,
100 * entry.getN2() / total, 100 * entry.getN3() / total};
entries.add(new BarEntry(/*long*/entry.getDate(), y));
}
count = entries.size();
final BarDataSet dataset …Run Code Online (Sandbox Code Playgroud) 我正在使用MPAndroidChart(https://github.com/PhilJay/MPAndroidChart)库生成饼图。我遵循了包括Wiki页面在内的多个教程,但是当我创建饼图时,所有部分都是相同的颜色。知道我该如何解决吗?
码:
PieChart mChart = (PieChart) findViewById(R.id.piechart);
List<PieEntry> pieChartEntries = new ArrayList<>();
pieChartEntries.add(new PieEntry(18.5f, "Green"));
pieChartEntries.add(new PieEntry(26.7f, "Yellow"));
pieChartEntries.add(new PieEntry(24.0f, "Red"));
pieChartEntries.add(new PieEntry(30.8f, "Blue"));
PieDataSet set = new PieDataSet(pieChartEntries, "Emotion Results");
PieData data = new PieData(set);
mChart.setData(data);
set.setColors(R.color.pieColour1,R.color.pieColour2,R.color.pieColour3,R.color.pieColour4,R.color.pieColour5,R.color.pieColour6,R.color.pieColour7,R.color.pieColour8);
mChart.invalidate();
Run Code Online (Sandbox Code Playgroud)
我希望x轴标记如上图所示.我尝试过使用AxisValueFormatter接口,但它的作用是从0到1重复标签'jh ow'3次,同时错过了这里显示的一些标签.
这是我得到的输出.虽然图形的形状是正确的,但标签不是.
我正在分享图表数据,以便有兴趣的人可以尝试制作如图所示的图表.任何帮助都会很棒,谢谢.
使用MPAndroid并不重要.任何其他图书馆的任何帮助也很好.
数据是:
"lables" : ["jh ow", "n ih l", "b iy", "hh iy r", "s uw n"]
"values":[[{"x":"0.00","y":"0.00"},{"x":"0.99","y":"0.00"}],
[{"x":"0.99","y":"1.00"},{"x":"1.19","y":"0.50"}]
, [{"x":"1.19","y":"0.50"},{"x":"1.37","y":"0.50"}]
, [{"x":"1.37","y":"0.50"},{"x":"1.59","y":"0.50"}]
, [{"x":"1.59","y":"0.50"},{"x":"2.12","y":"1.00"}]]
Run Code Online (Sandbox Code Playgroud)