2

在这里,我试图在 x 轴上显示一个图表,其中的值是从网络服务器检索的:

// Our first data

Date[] x = dates_array; // x values!

double[] y =  readings_array; // y values!



                XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); // Holds a collection of XYSeriesRenderer and customizes the graph
                XYSeriesRenderer renderer = new XYSeriesRenderer(); // This will be used to customize line 1
                XYSeriesRenderer renderer2 = new XYSeriesRenderer(); // This will be used to customize line 2
                mRenderer.addSeriesRenderer(renderer);
                mRenderer.addSeriesRenderer(renderer2);
                TimeSeries series = new TimeSeries("peak flow"); 
                for( int i = 0; i < x.length; i++)
                {
                    series.add(x[i], y[i]);
                }

                // Our second data
            int[] x2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // x values!




                int[] y2 =  { 145, 123, 111, 100, 89, 77, 57, 45, 34, 30}; // y values!
                TimeSeries series2 = new TimeSeries("Line2"); 
                for( int i = 0; i < x2.length; i++)
                {
                    series2.add(x2[i], y2[i]);

                }

                XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                dataset.addSeries(series);
                dataset.addSeries(series2);



                // Customization time for line 1!
                renderer.setColor(Color.WHITE);
                renderer.setPointStyle(PointStyle.SQUARE);
                renderer.setFillPoints(true);
                // Customization time for line 2!
                renderer2.setColor(Color.YELLOW);
                renderer2.setPointStyle(PointStyle.DIAMOND);
                renderer2.setFillPoints(true);



                Intent intent = ChartFactory.getTimeChartIntent(getApplicationContext(), dataset,
                     mRenderer, "DD MMM yyyy");
                startActivity(intent);
            }
        });

它适用于 y 轴,但在 x 轴上显示的值是随机值而不是我的值!请问有什么帮助吗?

4

1 回答 1

1

TimeSeries你应该使用的add(Date x, double y)方法,而不是add(double x, double y)一个。

如果您希望 X 轴标签恰好是数据的日期,请执行以下操作:

renderer.setXRoundedLabels(false);
于 2012-11-04T16:22:05.620 回答