标签: mpandroidchart

在android中使用MPAndroidChart从数据库中检索数据并在条形图中显示它们

我知道如何使用 MPAndroidChart 在条形图中显示原始数据,但我在实际场景中遇到了问题。我的 sqlite 数据库中有一些数据,我想在条形图中显示它们。请给我一些参考或简单的例子。

数据库表有两列月份和一些数字。例如:一月 = 200,二月 = 300,等等。

我搜索了很多,但找不到合适的。他们要么是 2-3 岁,要么不是我提到的那种类型。

提前致谢。

database sqlite android mpandroidchart

1
推荐指数
1
解决办法
5135
查看次数

重叠数据标签 (MPAndroidChart)

如果我有很多具有接近值的值,则数据标签会重叠。例如这个 14 的序列:

在此处输入图片说明

有没有办法以某种方式消除混乱或“隐藏”导致混乱的标签?

java android graph mpandroidchart

1
推荐指数
1
解决办法
3434
查看次数

MPAndroidChart:如何创建双轴?

我正在使用MPAndroidChart绘制折线图。

我需要绘制一个双 Y 轴折线图(即有 2 个 Y 轴,一个在左边,另一个在右边)。但是当我绘制图形时,它是从左侧绘制的。它考虑了左 YAxis 值而不是右 YAxis 值。

我在右侧绘制重量(公斤),在左侧绘制高度(英尺)。由于重量将按照 40 秒、50 秒等表示,而高度将按照 5、6 等表示……为高度绘制的线采用左参考,它有 50 秒、60 秒,因此永远不会出现。

请让我知道如何直接绘制考虑到高度的右 Y 轴而不是左 Y 轴。

android mpandroidchart

1
推荐指数
1
解决办法
1289
查看次数

我正在尝试使用 MP android 图表将 X 轴的值显示在图表的底部而不是顶部

我使用 MP android 图表创建了一个图形应用程序,我用它来绘制两个不同的线数据集。但我的问题是 xaxis 的值标签出现在图的顶部。我需要一种方法让它到达底部。下面是我的代码

final LineChart linechart = (LineChart)findViewById(R.id.idlinechart);

        //created list enties to hold the values
        List<Entry> valuesCompany1 = new ArrayList<>();  List<Entry> valuesCompany2 = new ArrayList<>();
//created entry values to be entered into the lsit entry b
        Entry c1e1 = new Entry(0f, 100000f); valuesCompany1.add(c1e1);

        Entry c1e2 = new Entry (1f, 140000f);valuesCompany1.add(c1e2);

        Entry c1e3 = new Entry(2f,90000f);valuesCompany1.add(c1e3);

        Entry c1e4 = new Entry (3f, 150000f); valuesCompany1.add(c1e4);

        Entry c2e1 = new Entry(0f, 50000f); valuesCompany2.add(c2e1);

        Entry c2e2 = new Entry (1f, 50000f);valuesCompany2.add(c2e2); …
Run Code Online (Sandbox Code Playgroud)

android mpandroidchart

1
推荐指数
1
解决办法
1986
查看次数

如何使用 Mikephil 饼图从项目中删除小数位

这是整数的静态值

  private int upload=14, bill=15, unbill=85, total=100, unupload=12, sign=10, unsign=90, print=12, unprint=88;
Run Code Online (Sandbox Code Playgroud)

设置饼图的入口

ArrayList<Entry> entries = new ArrayList<>();

entries.add(new Entry(bill, 0));
entries.add(new Entry(unbill, 1));
entries.add(new Entry(print, 2));
entries.add(new Entry(unprint, 3));
entries.add(new Entry(sign, 4));
entries.add(new Entry(unsign, 5));
entries.add(new Entry(upload, 6));
entries.add(new Entry(unupload, 7));

 int colors[] ={Color.rgb(84, 139, 221), Color.rgb(251, 249, 146),Color.rgb(151, 212, 153), Color.rgb(183, 144, 189),Color.rgb(226, 148, 188),Color.rgb(208, 189, 121),Color.rgb(185, 147, 134),Color.rgb(206, 139, 130)};
Run Code Online (Sandbox Code Playgroud)

这里我使用 Mikephil PieChart,下面我在数据集中添加了条目。

PieDataSet dataset = new PieDataSet(entries, "Graph");
dataset.setColors(colors);
dataset.setSliceSpace(3f);
Run Code Online (Sandbox Code Playgroud)

我得到这个输出。所以我想删除我提到的小数位图片

输出完美。我只想要没有小数位的输出。我怎样才能做到这一点?

android mpandroidchart

1
推荐指数
1
解决办法
1681
查看次数

MPAndroidChart条形图值

我已经阅读了MPAndroidChart的文档(使用v3.0.1),但似乎找不到删除条形标签的方法。

样本图

我想隐藏显示在每个栏顶部的值,或者将它们的值更改为我可以手动设置的值。两种选择都适合我的实现。

我不确定是否有可能两者之一。我对android开发非常陌生,任何帮助都会很棒。

我的代码是:

public class MainActivity extends AppCompatActivity {

protected BarChart chart;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    chart = (BarChart) findViewById(R.id.chart1);

    Description desc ;
    Legend L;

    L = chart.getLegend();
    desc = chart.getDescription();
    desc.setText(""); // this is the weirdest way to clear something!!
    L.setEnabled(false);


    YAxis leftAxis = chart.getAxisLeft();
    YAxis rightAxis = chart.getAxisRight();
    XAxis xAxis = chart.getXAxis();

    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTextSize(10f);
    xAxis.setDrawAxisLine(true);
    xAxis.setDrawGridLines(false);


    leftAxis.setTextSize(10f);
    leftAxis.setDrawLabels(false);
    leftAxis.setDrawAxisLine(true);
    leftAxis.setDrawGridLines(false);

    rightAxis.setDrawAxisLine(false);
    rightAxis.setDrawGridLines(false);
    rightAxis.setDrawLabels(false);

    BarData data = new BarData(  setData());


    data.setBarWidth(0.9f); // set custom …
Run Code Online (Sandbox Code Playgroud)

android mpandroidchart

1
推荐指数
2
解决办法
4640
查看次数

MPAndroidChart:如何删除网格线?

在我LineChart旁边的平行于x轴的全数字上显示的线条中,显示了许多水平网格线:

在此输入图像描述

在此输入图像描述

我怎么能摆脱这些线?

android linechart mpandroidchart

1
推荐指数
1
解决办法
1504
查看次数

MPAndroidChart setGranularity(1.0f) 不起作用

我真的很感谢这个图书馆。我正在尝试绘制水平条形图。

但是我遇到了一个问题。我想每一点绘制图表轴。所以我使用了“setGranularity(1.0f);”

但是轴每 2 点显示一次。当我使用“setGranularity(3.0f)”或更高版本时,它工作正常。但是 1.0 不起作用。我不知道为什么。而且我能找到线索。

当“List”的大小小于 8 时,“setGranularity(1.0f)”工作正常。在此处输入图片说明

当“List”的大小大于 9 时,“setGranularity(1.0f)”不起作用。(它的工作原理类似于“setGranularity(2.0f)”。)在此处输入图片说明

我的列表大小为 13。

如何应用“setGranularity(1.0f)”?

android mpandroidchart

1
推荐指数
1
解决办法
1978
查看次数

X 轴标签未显示,使用 MPAndroidChart

我想在我的折线图上有 x 轴标签(使用MPAndroidChart),但无论我做什么,我都无法显示它们。我有一个名为 setupChart 的方法,它处理该图表的所有内容,它是这样的:

private void setupChart(LineChart chart, LineData data, int color) {

    ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(Color.WHITE);
    ((LineDataSet) data.getDataSetByIndex(0)).setCircleColor(color);
    ((LineDataSet) data.getDataSetByIndex(0)).setColors(dataColors);
    data.getDataSetByIndex(0).setAxisDependency(YAxis.AxisDependency.LEFT);
    ((LineDataSet) data.getDataSetByIndex(0)).setDrawCircles(false);

    // no description text
    chart.getDescription().setEnabled(false);

    // mChart.setDrawHorizontalGrid(false);
    //
    // enable / disable grid background
    chart.setDrawGridBackground(false);

    // enable touch gestures
    chart.setTouchEnabled(true);

    // disable scaling and dragging
    chart.setDragEnabled(false);
    chart.setScaleEnabled(false);
    chart.setAutoScaleMinMaxEnabled(false);
    // if disabled, scaling can be done on x- and y-axis separately
    chart.setPinchZoom(false);
    chart.setBackgroundColor(Color.parseColor("#dddddd"));

    // set custom chart offsets (automatic offset calculation is hereby disabled)
    chart.setViewPortOffsets(10, 0, …
Run Code Online (Sandbox Code Playgroud)

java android mpandroidchart

1
推荐指数
2
解决办法
4152
查看次数

将当前时间(以毫秒为单位)传递给 MPChart 会破坏它

我试图弄清楚这一点,但它没有加起来。数据未按预期显示。

首先我生成虚拟数据。这是异步完成的,因为我需要在两次调用System.currentTimeMillis之间留出时间来获得它们之间的一些间距。(看看这里糟糕的代码,这只是不会在发布中的调试数据。考虑到 ANR,在主线程上使用 Thread.sleep 是个坏主意)

public class AsyncGeneration extends AsyncTask<String, String, String>{
    public AsyncGeneration() {
        super();
    }
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }
    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
    }
    @Override
    protected void onProgressUpdate(String... values) {
        super.onProgressUpdate(values);
    }
    @Override
    protected void onCancelled(String s) {
        super.onCancelled(s);
    }
    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
    @Override
    protected String doInBackground(String... strings) {
        while(root == null) {
            try {
                Thread.sleep(200);
            }catch(InterruptedException e){}
        }
        List<Entry> rdata = new ArrayList<>();
        for(int i …
Run Code Online (Sandbox Code Playgroud)

android mpandroidchart

1
推荐指数
1
解决办法
1603
查看次数

标签 统计

android ×10

mpandroidchart ×10

java ×2

database ×1

graph ×1

linechart ×1

sqlite ×1