在 Android 中绘制图表

发布于 2024-11-07 14:18:50 字数 2512 浏览 0 评论 0原文

我想在Android中画一个图表,在X轴上我想要像一月,二月,三月,四月,五月,六月,八月,九月,十月,十一月,十二月这样的月份,在Y轴上你花多少钱特定月份。

我有一个在 android 上绘制图表的代码:-

mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
        Number[] series1Numbers = { 1, 8, 5, 2, 7, 4 };
        Number[] series2Numbers = { 4, 6, 3, 8, 2, 10 };
        XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numbers),
        SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,"Series1");
        XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers),
        SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");

        LineAndPointFormatter series1Format = new LineAndPointFormatter(
                Color.rgb(0, 200, 0), // line color
                Color.rgb(0, 100, 0), // point color
                Color.rgb(150, 190, 150)); // fill color (optional)
                mySimpleXYPlot.addSeries(series1, series1Format);
                mySimpleXYPlot.addSeries(
                series2,
                new LineAndPointFormatter(Color.rgb(0, 0, 200),
                Color.rgb(0, 0, 100), Color.rgb(150, 150, 190)));
                mySimpleXYPlot.setTicksPerRangeLabel(3);
                }

但我想在 X 轴上显示月份,在 Y 轴上显示他们在该月花费的具体金额。这些值来自数据库,他们花钱的月份以 mon 他们花费的所需月份的形式出现,名称包含他们在该月花费的值。

try {
        myDB = this.openOrCreateDatabase("Expense_db", MODE_PRIVATE, null);

        Cursor c = myDB.rawQuery("SELECT project_android.Month AS Month_Real, " +
                  "SUM(Total) AS OrderTotal FROM project_android " +
                  "WHERE Year='"+value1+"' " +
                  "GROUP BY project_android.Month " , null);

                     int Column1 = c.getColumnIndex("Month_Real");
                     int Column2 = c.getColumnIndex("OrderTotal");
                     //int current=0;
                  // Check if our result was valid.
                     c.moveToFirst();
                     if (c != null) {
                      // Loop through all Results
                     do {
                       mon = c.getString(Column1);               
                       Name = c.getDouble(Column2);
                       Log.i(TAG, "Testing_value_graph_month: " + Name + " | " + mon + " " );

                     }while(c.moveToNext());
                     c.close();
                     }
                     }
    catch(Exception e) {
        Log.e("Error", "Error", e);
       } finally {
        if (myDB != null)
         myDB.close();
       }

任何帮助将不胜感激..!

I wanted to draw a graph in Android such that on X axis I want Months like Jan, Feb, March, Apr, May, Jun, Aug, Sep, Oct, Nov, Dec and on Y axis the amount how much you spending in that particular month.

I have a code that draw the graph on an android:-

mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
        Number[] series1Numbers = { 1, 8, 5, 2, 7, 4 };
        Number[] series2Numbers = { 4, 6, 3, 8, 2, 10 };
        XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numbers),
        SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,"Series1");
        XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers),
        SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");

        LineAndPointFormatter series1Format = new LineAndPointFormatter(
                Color.rgb(0, 200, 0), // line color
                Color.rgb(0, 100, 0), // point color
                Color.rgb(150, 190, 150)); // fill color (optional)
                mySimpleXYPlot.addSeries(series1, series1Format);
                mySimpleXYPlot.addSeries(
                series2,
                new LineAndPointFormatter(Color.rgb(0, 0, 200),
                Color.rgb(0, 0, 100), Color.rgb(150, 150, 190)));
                mySimpleXYPlot.setTicksPerRangeLabel(3);
                }

But I want on X Axis the Months and on Y axis particular amount they spend in that month. and these values are coming from database, month in which they are spending money in the form of mon the reuqired month they spend and Name contains the value they spend in that month.

try {
        myDB = this.openOrCreateDatabase("Expense_db", MODE_PRIVATE, null);

        Cursor c = myDB.rawQuery("SELECT project_android.Month AS Month_Real, " +
                  "SUM(Total) AS OrderTotal FROM project_android " +
                  "WHERE Year='"+value1+"' " +
                  "GROUP BY project_android.Month " , null);

                     int Column1 = c.getColumnIndex("Month_Real");
                     int Column2 = c.getColumnIndex("OrderTotal");
                     //int current=0;
                  // Check if our result was valid.
                     c.moveToFirst();
                     if (c != null) {
                      // Loop through all Results
                     do {
                       mon = c.getString(Column1);               
                       Name = c.getDouble(Column2);
                       Log.i(TAG, "Testing_value_graph_month: " + Name + " | " + mon + " " );

                     }while(c.moveToNext());
                     c.close();
                     }
                     }
    catch(Exception e) {
        Log.e("Error", "Error", e);
       } finally {
        if (myDB != null)
         myDB.close();
       }

Any help will be appreciated..!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

家住魔仙堡 2024-11-14 14:18:50

我使用这个

Click Here

代码来满足相同的要求希望它会帮助你

I used this

Click Here

code for same requirement hope it will help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文