使用Achartengine绘制垂直折线图

时间:2013-08-12 10:17:09

标签: android charts

我正在开发一个我需要实现线图的应用程序。

因为我使用Achart引擎绘制折线图,​​但我想使用一些样本坐标绘制垂直线,但我没能实现它。但是我可以绘制水平线,但不能绘制垂直直线。

 int[] x = { 1,2,3,4,5,6,7,8 };
                    int[] systolic = { 90,90,100,70,90,100,110,70};
                    //int[] systolic = { 90,90,90,90,90,90,90,90};
                  /*  int[] diastolic = {70, 60, 65, 70, 45, 60, 70, 90 };
                    int[] pulse = {45, 60, 45, 80, 65, 50, 90, 70};*/

                    // Creating an  XYSeries for Income
                    XYSeries systolicSeries = new XYSeries("Systolic");
                    // Creating an  XYSeries for Expense
                    XYSeries diastolicSeries = new XYSeries("Diastolic");
                    // Creating an  XYSeries for Expense
                    XYSeries pulseSeries = new XYSeries("Pulse");

                    // Adding data to Income and Expense Series
                    for(int i=0;i<x.length;i++){
                        systolicSeries.add(x[1], systolic[i]);
                      //  diastolicSeries.add(x[i],diastolic[i]);
                      //  pulseSeries.add(x[i],pulse[i]);
                    }

                    // Creating a dataset to hold each series
                    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                    // Adding Income Series to the dataset
                    dataset.addSeries(systolicSeries);
                    // Adding Expense Series to dataset
                  //  dataset.addSeries(diastolicSeries);
                    // Adding Expense Series to dataset
                  //  dataset.addSeries(pulseSeries);



                    // Creating XYSeriesRenderer to customize incomeSeries
                    XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
                    incomeRenderer.setColor(Color.WHITE);
                    incomeRenderer.setPointStyle(PointStyle.CIRCLE);
                    incomeRenderer.setFillPoints(true);
                    incomeRenderer.setLineWidth(2);
                    incomeRenderer.setDisplayChartValues(true);

                /*    // Creating XYSeriesRenderer to customize expenseSeries
                    XYSeriesRenderer expenseRenderer = new XYSeriesRenderer();
                    expenseRenderer.setColor(Color.YELLOW);
                    expenseRenderer.setPointStyle(PointStyle.CIRCLE);
                    expenseRenderer.setFillPoints(true);
                    expenseRenderer.setLineWidth(2);
                    expenseRenderer.setDisplayChartValues(true);

                 // Creating XYSeriesRenderer to customize incomeSeries
                    XYSeriesRenderer pulseRenderer = new XYSeriesRenderer();
                    incomeRenderer.setColor(Color.WHITE);
                    incomeRenderer.setPointStyle(PointStyle.CIRCLE);
                    incomeRenderer.setFillPoints(true);
                    incomeRenderer.setLineWidth(2);
                    incomeRenderer.setDisplayChartValues(true);*/

                    // Creating a XYMultipleSeriesRenderer to customize the whole chart
                    XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
                    multiRenderer.setXLabels(0);
                    multiRenderer.setChartTitle("Blood Pressure");
                    multiRenderer.setXTitle("Date");
                    multiRenderer.setYTitle("Value");
                    multiRenderer.setZoomButtonsVisible(true);
                    for(int i=0;i<x.length;i++){
                        multiRenderer.addXTextLabel(i+1, mMonth[i]);
                    }

                    // Adding incomeRenderer and expenseRenderer to multipleRenderer
                    // Note: The order of adding dataseries to dataset and renderers to multipleRenderer
                    // should be same
                    multiRenderer.addSeriesRenderer(incomeRenderer);
                  //  multiRenderer.addSeriesRenderer(expenseRenderer);
                  //  multiRenderer.addSeriesRenderer(pulseRenderer);

                    mChartView = ChartFactory.getLineChartView(this, dataset, multiRenderer);
                    mChartView.setBackgroundColor(Color.BLACK);

                    linlayChartLogContainer.addView(mChartView);

                }
            catch (Exception e)
                {
                    e.printStackTrace();
                }

1 个答案:

答案 0 :(得分:0)

您是否在AchartEngine中尝试过Bar-Chart?它可以绘制垂直线