Java Code Examples for lecho.lib.hellocharts.model.LineChartData#setAxisXBottom()

The following examples show how to use lecho.lib.hellocharts.model.LineChartData#setAxisXBottom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatisticViewModel.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
private LineChartData getLineChartData(List<Line> lines) {
    DateTime daysAgo = new DateTime().withTimeAtStartOfDay().minusDays(StatisticViewModel.DAYS_OF_ADDED_MODEL - 1);
    List<String> days = new ArrayList<>();
    SimpleDateFormat sdf = new SimpleDateFormat("dd", Locale.getDefault());
    for (int i=0; i<StatisticViewModel.DAYS_OF_ADDED_MODEL; i++){
        days.add(sdf.format(daysAgo.toDate()));
        daysAgo = daysAgo.plusDays(1);
    }

    LineChartData data = new LineChartData();
    data.setLines(lines);
    data.setAxisXBottom(null);
    data.setAxisYLeft(null);
    data.setBaseValue(-0.1f);
    data.setValueLabelBackgroundColor(Color.TRANSPARENT);
    Axis axis = Axis.generateAxisFromCollection(Arrays.asList(0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f), days);
    data.setAxisXBottom(axis);
    return data;
}
 
Example 2
Source File: ViewPagerChartsActivity.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
private LineChartData generateLineChartData() {
    int numValues = 20;

    List<PointValue> values = new ArrayList<PointValue>();
    for (int i = 0; i < numValues; ++i) {
        values.add(new PointValue(i, (float) Math.random() * 100f));
    }

    Line line = new Line(values);
    line.setColor(ChartUtils.COLOR_GREEN);

    List<Line> lines = new ArrayList<Line>();
    lines.add(line);

    LineChartData data = new LineChartData(lines);
    data.setAxisXBottom(new Axis().setName("Axis X"));
    data.setAxisYLeft(new Axis().setName("Axis Y").setHasLines(true));
    return data;

}
 
Example 3
Source File: MetricGaugeFragment.java    From hawkular-android-client with Apache License 2.0 6 votes vote down vote up
private void setUpChartLine() {
    List<PointValue> chartPoints = getChartPoints();
    List<AxisValue> chartAxisPoints = getChartAxisPoints();

    Line chartLine = new Line(chartPoints)
        .setColor(getResources().getColor(R.color.background_primary_dark))
        .setCubic(true)
        .setHasPoints(false);

    LineChartData chartData = new LineChartData()
        .setLines(Collections.singletonList(chartLine));
    chartData.setAxisXBottom(new Axis()
        .setValues(chartAxisPoints));
    chartData.setAxisYLeft(new Axis()
        .setHasLines(true));

    chart.setLineChartData(chartData);
}
 
Example 4
Source File: MetricCounterFragment.java    From hawkular-android-client with Apache License 2.0 6 votes vote down vote up
private void setUpChartLine() {
    List<PointValue> chartPoints = getChartPoints();
    List<AxisValue> chartAxisPoints = getChartAxisPoints();

    Line chartLine = new Line(chartPoints)
            .setColor(getResources().getColor(R.color.background_primary_dark))
            .setCubic(true)
            .setHasPoints(false);

    LineChartData chartData = new LineChartData()
            .setLines(Collections.singletonList(chartLine));
    chartData.setAxisXBottom(new Axis()
            .setValues(chartAxisPoints));
    chartData.setAxisYLeft(new Axis()
            .setHasLines(true));

    chart.setLineChartData(chartData);
}
 
Example 5
Source File: PreviewLineChartActivity.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
private void generateDefaultData() {
    int numValues = 50;

    List<PointValue> values = new ArrayList<PointValue>();
    for (int i = 0; i < numValues; ++i) {
        values.add(new PointValue(i, (float) Math.random() * 100f));
    }

    Line line = new Line(values);
    line.setColor(ChartUtils.COLOR_GREEN);
    line.setHasPoints(false);// too many values so don't draw points.

    List<Line> lines = new ArrayList<Line>();
    lines.add(line);

    data = new LineChartData(lines);
    data.setAxisXBottom(new Axis());
    data.setAxisYLeft(new Axis().setHasLines(true));

    // prepare preview data, is better to use separate deep copy for preview chart.
    // Set color to grey to make preview area more visible.
    previewData = new LineChartData(data);
    previewData.getLines().get(0).setColor(ChartUtils.DEFAULT_DARKEN_COLOR);

}
 
Example 6
Source File: LineColumnDependencyActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
/**
 * Generates initial data for line chart. At the begining all Y values are equals 0. That will change when user
 * will select value on column chart.
 */
private void generateInitialLineData() {
    int numValues = 7;

    List<AxisValue> axisValues = new ArrayList<AxisValue>();
    List<PointValue> values = new ArrayList<PointValue>();
    for (int i = 0; i < numValues; ++i) {
        values.add(new PointValue(i, 0));
        axisValues.add(new AxisValue(i).setLabel(days[i]));
    }

    Line line = new Line(values);
    line.setColor(ChartUtils.COLOR_GREEN).setCubic(true);

    List<Line> lines = new ArrayList<Line>();
    lines.add(line);

    lineData = new LineChartData(lines);
    lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true));
    lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(3));

    chartTop.setLineChartData(lineData);

    // For build-up animation you have to disable viewport recalculation.
    chartTop.setViewportCalculationEnabled(false);

    // And set initial max viewport and current viewport- remember to set viewports after data.
    Viewport v = new Viewport(0, 110, 6, 0);
    chartTop.setMaximumViewport(v);
    chartTop.setCurrentViewport(v);

    chartTop.setZoomType(ZoomType.HORIZONTAL);
}
 
Example 7
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
public Bitmap build() {
    List<Line> lines = new ArrayList<>();
    bgGraphBuilder.defaultLines();
    lines.add(bgGraphBuilder.inRangeValuesLine());
    lines.add(bgGraphBuilder.lowValuesLine());
    lines.add(bgGraphBuilder.highValuesLine());
    if (showLowLine)
        lines.add(bgGraphBuilder.lowLine());
    if (showHighLine)
        lines.add(bgGraphBuilder.highLine());
    if (useSmallDots) {
        for(Line line: lines)
            line.setPointRadius(2);
    }
    LineChartData lineData = new LineChartData(lines);
    if (showAxes) {
        lineData.setAxisYLeft(bgGraphBuilder.yAxis());
        lineData.setAxisXBottom(bgGraphBuilder.xAxis());
    }
    //lines.add(bgGraphBuilder.rawInterpretedLine());
    chart.setLineChartData(lineData);
    Viewport viewport = chart.getMaximumViewport();
    viewport.left = start;
    viewport.right = end;
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0, 0, 0, 0);
    chart.setLeft(0);
    chart.setTop(0);
    chart.setRight(width);
    chart.setBottom(height);
    return getViewBitmap(chart);
}
 
Example 8
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
Bitmap build() {
    List<Line> lines = new ArrayList<>();
    bgGraphBuilder.defaultLines();
    lines.add(bgGraphBuilder.inRangeValuesLine());
    lines.add(bgGraphBuilder.lowValuesLine());
    lines.add(bgGraphBuilder.highValuesLine());
    if (showLowLine)
        lines.add(bgGraphBuilder.lowLine());
    if (showHighLine)
        lines.add(bgGraphBuilder.highLine());
    if (useSmallDots) {
        for(Line line: lines)
            line.setPointRadius(1);
    }
    LineChartData lineData = new LineChartData(lines);
    if (showAxes) {
        lineData.setAxisYLeft(bgGraphBuilder.yAxis());
        lineData.setAxisXBottom(bgGraphBuilder.xAxis());
    }
    //lines.add(bgGraphBuilder.rawInterpretedLine());
    chart.setLineChartData(lineData);
    Viewport viewport = chart.getMaximumViewport();
    viewport.left = start;
    viewport.right = end;
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0,0,0,0);
    chart.setLeft(0);
    chart.setTop(0);
    chart.setRight(width);
    chart.setBottom(height);
    return getViewBitmap(chart);
}
 
Example 9
Source File: IOBCOBLineGraph.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
public LineChartData iobcobPastLineData() {
    LineChartData lineData = new LineChartData(iobcobPastdefaultLines());
    lineData.setAxisYLeft(iobPastyAxis());
    lineData.setAxisYRight(cobPastyAxis());
    lineData.setAxisXBottom(xAxis());
    Log.d(TAG, "Updated");
    return lineData;
}
 
Example 10
Source File: BasalVSTempBasalGraph.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
public LineChartData basalvsTempBasalData() {
    LineChartData lineData = new LineChartData(addBasalvsTempBasaLines());
    lineData.setAxisYLeft(basalVsTempBasalyAxis());
    //lineData.setAxisYRight(cobPastyAxis());
    lineData.setAxisXBottom(xAxis());
    return lineData;
}
 
Example 11
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
public Bitmap build() {
    List<Line> lines = new ArrayList<>();
    bgGraphBuilder.defaultLines();
    lines.add(bgGraphBuilder.inRangeValuesLine());
    lines.add(bgGraphBuilder.lowValuesLine());
    lines.add(bgGraphBuilder.highValuesLine());
    if (showLowLine)
        lines.add(bgGraphBuilder.lowLine());
    if (showHighLine)
        lines.add(bgGraphBuilder.highLine());
    if (useSmallDots) {
        for(Line line: lines)
            line.setPointRadius(2);
    }
    LineChartData lineData = new LineChartData(lines);
    if (showAxes) {
        lineData.setAxisYLeft(bgGraphBuilder.yAxis());
        lineData.setAxisXBottom(bgGraphBuilder.xAxis());
    }
    //lines.add(bgGraphBuilder.rawInterpretedLine());
    chart.setLineChartData(lineData);
    Viewport viewport = chart.getMaximumViewport();
    viewport.left = start;
    viewport.right = end;
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0, 0, 0, 0);
    chart.setLeft(0);
    chart.setTop(0);
    chart.setRight(width);
    chart.setBottom(height);
    return getViewBitmap(chart);
}
 
Example 12
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
Bitmap build() {
    List<Line> lines = new ArrayList<>();
    bgGraphBuilder.defaultLines();
    lines.add(bgGraphBuilder.inRangeValuesLine());
    lines.add(bgGraphBuilder.lowValuesLine());
    lines.add(bgGraphBuilder.highValuesLine());
    if (showLowLine)
        lines.add(bgGraphBuilder.lowLine());
    if (showHighLine)
        lines.add(bgGraphBuilder.highLine());
    if (useSmallDots) {
        for(Line line: lines)
            line.setPointRadius(1);
    }
    LineChartData lineData = new LineChartData(lines);
    if (showAxes) {
        lineData.setAxisYLeft(bgGraphBuilder.yAxis());
        lineData.setAxisXBottom(bgGraphBuilder.xAxis());
    }
    //lines.add(bgGraphBuilder.rawInterpretedLine());
    chart.setLineChartData(lineData);
    Viewport viewport = chart.getMaximumViewport();
    viewport.left = start;
    viewport.right = end;
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0,0,0,0);
    chart.setLeft(0);
    chart.setTop(0);
    chart.setRight(width);
    chart.setBottom(height);
    return getViewBitmap(chart);
}
 
Example 13
Source File: LineCharts.java    From MetalDetector with GNU General Public License v3.0 5 votes vote down vote up
/**
* 初始化图表数据
* */

protected LineChartData initData(List<Line> lines) {
    LineChartData data = new LineChartData(lines);
    data.setAxisYLeft(axisY);
    data.setAxisXBottom(axisX);
    return data;
}
 
Example 14
Source File: LibreTrendGraph.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public void setupCharts() {
    
   final TextView trendView = (TextView) findViewById(R.id.textLibreHeader);
     
    chart = (LineChartView) findViewById(R.id.libre_chart);
    List<Line> lines = new ArrayList<Line>();

    List<PointValue> lineValues = new ArrayList<PointValue>();
    final float conversion_factor_mmol = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL);

    LibreBlock libreBlock= LibreBlock.getLatestForTrend();
    if(libreBlock == null) {
        trendView.setText("No libre data to display");
        setupEmptyCharts();
        return;
    }
    String time = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date((long) libreBlock.timestamp));

    ArrayList<Float> bg_data = getLatestBgForXMinutes(MINUTES_TO_DISPLAY);
    
    if(bg_data == null) {
        trendView.setText("Error displaying data for " + time);
        setupEmptyCharts();
        return;
    }
    
    trendView.setText("Scan from " + time);
    float min = 1000;
    float max = 0;
    int i = 0;
    for(float bg : bg_data ) {
        if(bg <= 0) {
            i++;
            continue;   
        }
        if(min > bg) {
            min = bg;
        }
        if(max < bg) {
            max = bg;
        }
        
        lineValues.add(new PointValue(-i, bg * conversion_factor_mmol));
        i++;
    }

    Line trendLine = new Line(lineValues);
    trendLine.setColor(ChartUtils.COLOR_RED);
    trendLine.setHasLines(false);
    trendLine.setHasPoints(true);
    trendLine.setPointRadius(3);
    lines.add(trendLine);
    
    final int MIN_GRAPH = 20;
    if(max - min < MIN_GRAPH)
    {
        // On relative flat trend the graph can look very noise althouth with the right resolution it is not that way.
        // I will add two dummy invisible points that will cause the graph to look with bigger Y range.
        float average = (max + min) /2;
        List<PointValue> dummyPointValues = new ArrayList<PointValue>();
        Line dummyPointLine = new Line(dummyPointValues);
        dummyPointValues.add(new PointValue(0, (average - MIN_GRAPH / 2) * conversion_factor_mmol));
        dummyPointValues.add(new PointValue(0, (average + MIN_GRAPH / 2) * conversion_factor_mmol));
        dummyPointLine.setColor(ChartUtils.COLOR_RED);
        dummyPointLine.setHasLines(false);
        dummyPointLine.setHasPoints(false);
        lines.add(dummyPointLine);
    }

    Axis axisX = new Axis();
    Axis axisY = new Axis().setHasLines(true);
    axisX.setTextSize(16);
    axisY.setTextSize(16);
    axisX.setName("Time from last scan");
    axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l"));

    data = new LineChartData(lines);
    data.setAxisXBottom(axisX);
    data.setAxisYLeft(axisY);
    chart.setLineChartData(data);

}
 
Example 15
Source File: LibreTrendGraph.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public void setupCharts() {
    
   final TextView trendView = (TextView) findViewById(R.id.textLibreHeader);
     
    chart = (LineChartView) findViewById(R.id.libre_chart);
    List<Line> lines = new ArrayList<Line>();

    List<PointValue> lineValues = new ArrayList<PointValue>();
    final float conversion_factor_mmol = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL);

    LibreBlock libreBlock= LibreBlock.getLatestForTrend();
    if(libreBlock == null) {
        trendView.setText("No libre data to display");
        setupEmptyCharts();
        return;
    }
    String time = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date((long) libreBlock.timestamp));

    ArrayList<Float> bg_data = getLatestBgForXMinutes(MINUTES_TO_DISPLAY);
    
    if(bg_data == null) {
        trendView.setText("Error displaying data for " + time);
        setupEmptyCharts();
        return;
    }
    
    trendView.setText("Scan from " + time);
    float min = 1000;
    float max = 0;
    int i = 0;
    for(float bg : bg_data ) {
        if(bg <= 0) {
            i++;
            continue;   
        }
        if(min > bg) {
            min = bg;
        }
        if(max < bg) {
            max = bg;
        }
        
        lineValues.add(new PointValue(-i, bg * conversion_factor_mmol));
        i++;
    }

    Line trendLine = new Line(lineValues);
    trendLine.setColor(ChartUtils.COLOR_RED);
    trendLine.setHasLines(false);
    trendLine.setHasPoints(true);
    trendLine.setPointRadius(3);
    lines.add(trendLine);
    
    final int MIN_GRAPH = 20;
    if(max - min < MIN_GRAPH)
    {
        // On relative flat trend the graph can look very noise althouth with the right resolution it is not that way.
        // I will add two dummy invisible points that will cause the graph to look with bigger Y range.
        float average = (max + min) /2;
        List<PointValue> dummyPointValues = new ArrayList<PointValue>();
        Line dummyPointLine = new Line(dummyPointValues);
        dummyPointValues.add(new PointValue(0, (average - MIN_GRAPH / 2) * conversion_factor_mmol));
        dummyPointValues.add(new PointValue(0, (average + MIN_GRAPH / 2) * conversion_factor_mmol));
        dummyPointLine.setColor(ChartUtils.COLOR_RED);
        dummyPointLine.setHasLines(false);
        dummyPointLine.setHasPoints(false);
        lines.add(dummyPointLine);
    }

    Axis axisX = new Axis();
    Axis axisY = new Axis().setHasLines(true);
    axisX.setTextSize(16);
    axisY.setTextSize(16);
    axisX.setName("Time from last scan");
    axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l"));

    data = new LineChartData(lines);
    data.setAxisXBottom(axisX);
    data.setAxisYLeft(axisY);
    chart.setLineChartData(data);

}
 
Example 16
Source File: CalibrationGraph.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public void setupCharts() {
    chart = (LineChartView) findViewById(R.id.chart);
    List<Line> lines = new ArrayList<Line>();

    //calibration values
    List<Calibration> calibrations = Calibration.allForSensor();
    List<Line> greyLines = getCalibrationsLine(calibrations, Color.parseColor("#66FFFFFF"));
    calibrations = Calibration.allForSensorInLastFourDays();
    List<Line> blueLines = getCalibrationsLine(calibrations, ChartUtils.COLOR_BLUE);

    Calibration calibration = Calibration.lastValid();
    if (calibration != null) {
        //set header
        DecimalFormat df = new DecimalFormat("#");
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);
        String Header = "slope = " + df.format(calibration.slope) + " intercept = " + df.format(calibration.intercept);
        GraphHeader.setText(Header);

        //red line
        List<PointValue> lineValues = new ArrayList<PointValue>();
        final float conversion_factor = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL);

        lineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (start_x * calibration.slope + calibration.intercept))));
        lineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (end_x * calibration.slope + calibration.intercept))));
        Line calibrationLine = new Line(lineValues);
        calibrationLine.setColor(ChartUtils.COLOR_RED);
        calibrationLine.setHasLines(true);
        calibrationLine.setHasPoints(false);
        lines.add(calibrationLine);

        // calibration plugin
        final CalibrationAbstract plugin = getCalibrationPluginFromPreferences();
        if (plugin != null) {
            final CalibrationAbstract.CalibrationData pcalibration = plugin.getCalibrationData();

            final List<PointValue> plineValues = new ArrayList<PointValue>();

            plineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(start_x, pcalibration)))));
            plineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(end_x, pcalibration)))));

            final Line pcalibrationLine = new Line(plineValues);
            pcalibrationLine.setColor(Color.parseColor(plugin_color));
            pcalibrationLine.setHasLines(true);
            pcalibrationLine.setHasPoints(false);
            lines.add(pcalibrationLine);
            PluginHeader.setText("(" + plugin.getAlgorithmName() + ")  " + "s = " + df.format(pcalibration.slope) + "  i = " + df.format(pcalibration.intercept));
            PluginHeader.setTextColor(Color.parseColor(plugin_color));
        }

        //add lines in order
        for (Line greyLine : greyLines) {
            lines.add(greyLine);
        }
        for (Line blueLine : blueLines) {
            lines.add(blueLine);
        }

    }
    Axis axisX = new Axis();
    Axis axisY = new Axis().setHasLines(true);
    axisX.setName("Raw Value");
    axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l"));


    data = new LineChartData(lines);
    data.setAxisXBottom(axisX);
    data.setAxisYLeft(axisY);
    chart.setLineChartData(data);

}
 
Example 17
Source File: LineChartPresenter.java    From MemoryCleaner with Apache License 2.0 4 votes vote down vote up
private void updateViews(int count, float percent) {
    //LineChartData updatedData = new LineChartData();
    mPointValues.add(new PointValue(count, percent));
    mAxisValues.add(
            new AxisValue(count).setLabel(TimeUtils.getSystemDate()));

    if (count > MAX_COUNT) {
        mPointValues.remove(0);
        mAxisValues.remove(0);
    }
    Line line = new Line(mPointValues).setColor(color)
                                      .setCubic(true)
                                      .setFilled(true)
                                      .setHasPoints(false);
    List<Line> lines = new ArrayList<>();
    lines.add(line);
    LineChartData updatedData = new LineChartData();
    updatedData.setLines(lines);
    // 坐标轴
    Axis axisX = new Axis(mAxisValues).setTextColor(color)
                                      .setHasLines(true)
                                      .setLineColor(color)
                                      .setTextSize(9)
                                      .setName("时间(HH:mm:ss)")
                                      .setMaxLabelChars(5); // X轴
    updatedData.setAxisXBottom(axisX);
    Axis axisY = new Axis().setHasLines(true)
                           .setTextColor(color)
                           .setLineColor(color)
                           .setMaxLabelChars(5)
                           .setName("内存占用率(%)"); // Y轴

    // 默认是3,只能看最后三个数字
    updatedData.setAxisYLeft(axisY);
    mLineChart.updateViews(percent, updatedData);
    // 设置行为属性,支持缩放、滑动以及平移
    //final Viewport v = new Viewport(mLineChartView.getMaximumViewport());
    ////v.top =v.top+10; //example max value
    ////v.bottom = v.bottom-10;  //example min value
    ////mLineChartView.setMaximumViewport(v);
    //v.left = v.left + 1; //current viewport will take only part of max viewport horizontally
    //v.right = v.right - 1;
    //mLineChartView.setCurrentViewport(v);
    ////Optional step: disable viewport recalculations, thanks to this animations will not change viewport automatically.
    //mLineChartView.setViewportCalculationEnabled(false);
}
 
Example 18
Source File: MainActivity.java    From healthgo with GNU General Public License v3.0 4 votes vote down vote up
private void initLineChart() {
        Line line = new Line(mPointValues).setColor(Color.parseColor("#FFFAFA"));  //折线的颜色(橙色)
        List<Line> lines = new ArrayList<>();
        line.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状  这里是圆形 (有三种 :ValueShape.SQUARE  ValueShape.CIRCLE  ValueShape.DIAMOND)
        line.setCubic(false);//曲线是否平滑,即是曲线还是折线
        line.setFilled(false);//是否填充曲线的面积
        line.setHasLabels(true);//曲线的数据坐标是否加上备注
//      line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据(设置了这个line.setHasLabels(true);就无效)
        line.setHasLines(true);//是否用线显示。如果为false 则没有曲线只有点显示
        line.setHasPoints(true);//是否显示圆点 如果为false 则没有原点只有点显示(每个数据点都是个大的圆点)
        lines.add(line);
        LineChartData data = new LineChartData();
        data.setLines(lines);

        //坐标轴
        Axis axisX = new Axis(); //X轴
        axisX.setHasTiltedLabels(true);  //X坐标轴字体是斜的显示还是直的,true是斜的显示
        axisX.setTextColor(Color.WHITE);  //设置字体颜色
        //axisX.setName("date");  //表格名称
        axisX.setTextSize(10);//设置字体大小
        axisX.setMaxLabelChars(8); //最多几个X轴坐标,意思就是你的缩放让X轴上数据的个数7<=x<=mAxisXValues.length
        axisX.setValues(mAxisXValues);  //填充X轴的坐标名称
        data.setAxisXBottom(axisX); //x 轴在底部
        //data.setAxisXTop(axisX);  //x 轴在顶部
        axisX.setHasLines(true); //x 轴分割线

        // Y轴是根据数据的大小自动设置Y轴上限(在下面我会给出固定Y轴数据个数的解决方案)
        Axis axisY = new Axis();

        axisY.setName("");//y轴标注
        // axisY.setTextSize(10);//设置字体大小
        axisY.setTextColor(Color.parseColor("#ffffff"));
        data.setAxisYLeft(axisY);  //Y轴设置在左边
        //data.setAxisYRight(axisY);  //y轴设置在右边


        //设置行为属性,支持缩放、滑动以及平移
        lineChart.setInteractive(true);
        lineChart.setZoomType(ZoomType.HORIZONTAL);
        lineChart.setMaxZoom((float) 2);//最大方法比例
        lineChart.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
        lineChart.setLineChartData(data);
        lineChart.setVisibility(View.VISIBLE);
        /**注:下面的7,10只是代表一个数字去类比而已
         * 当时是为了解决X轴固定数据个数。见(http://forum.xda-developers.com/tools/programming/library-hellocharts-charting-library-t2904456/page2);
         */
//        Viewport v = new Viewport(lineChart.getMaximumViewport());
//        v.left = 0;
//        v.right= 7;
//        lineChart.setCurrentViewport(v);
    }
 
Example 19
Source File: ClimateFragment.java    From homeassist with Apache License 2.0 4 votes vote down vote up
private void setupChart(ArrayList<Entity> histories) {

        DateFormat df = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZZZZ", Locale.ENGLISH));
        ArrayList<DataItem> mDataCurrent = new ArrayList<>();
        ArrayList<DataItem> mDataTarget = new ArrayList<>();
        for (Entity history : histories) {
            try {
                if (history.attributes.currentTemperature != null) {
                    mDataCurrent.add(new DataItem(df.parse(history.lastUpdated), history.attributes.currentTemperature.floatValue()));
                }

                mDataTarget.add(new DataItem(df.parse(history.lastUpdated), history.attributes.getTemperature().floatValue()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        Line currentLine = getLine(mDataCurrent, "#3366cc");
        Line targetLine = getLine(mDataTarget, "#dc3912");

        List<PointValue> yValues = new ArrayList<>();
        List<AxisValue> axisValues = new ArrayList<>();
        for (int x = 0; x < mDataTarget.size(); ++x) {
            DataItem dataItem = mDataTarget.get(x);
            float yValue = dataItem.getYValue();
            yValues.add(new PointValue(dataItem.getXValue(), yValue));
        }

        //In most cased you can call data model methods in builder-pattern-like manner.
        List<Line> lines = new ArrayList<>();
        lines.add(currentLine);
        lines.add(targetLine);

        LineChartData data = new LineChartData();
        data.setLines(lines);

        Axis axisY = new Axis().setHasLines(true);
        axisY.setName(mEntity.attributes.unitOfMeasurement);
        data.setAxisYLeft(axisY);

        Axis axisX;

        if (mDataCurrent.size() != 0) {
            axisX = getXAxis(mDataCurrent);
        } else if (mDataTarget.size() != 0) {
            axisX = getXAxis(mDataTarget);
        } else {
            axisX = new Axis().setName("Time (Last 24 Hours)");
        }

        data.setAxisXBottom(axisX);

        mChart.setLineChartData(data);
        mChart.setVisibility(View.VISIBLE);
    }
 
Example 20
Source File: LineChartActivity.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
private void generateData() {

            List<Line> lines = new ArrayList<Line>();
            for (int i = 0; i < numberOfLines; ++i) {

                List<PointValue> values = new ArrayList<PointValue>();
                for (int j = 0; j < numberOfPoints; ++j) {
                    values.add(new PointValue(j, randomNumbersTab[i][j]));
                }

                Line line = new Line(values);
                line.setColor(ChartUtils.COLORS[i]);
                line.setShape(shape);
                line.setCubic(isCubic);
                line.setFilled(isFilled);
                line.setHasLabels(hasLabels);
                line.setHasLabelsOnlyForSelected(hasLabelForSelected);
                line.setHasLines(hasLines);
                line.setHasPoints(hasPoints);
                line.setHasGradientToTransparent(hasGradientToTransparent);
                if (pointsHaveDifferentColor){
                    line.setPointColor(ChartUtils.COLORS[(i + 1) % ChartUtils.COLORS.length]);
                }
                lines.add(line);
            }

            data = new LineChartData(lines);

            if (hasAxes) {
                Axis axisX = new Axis();
                Axis axisY = new Axis().setHasLines(true);
                if (hasAxesNames) {
                    axisX.setName("Axis X");
                    axisY.setName("Axis Y");
                }
                data.setAxisXBottom(axisX);
                data.setAxisYLeft(axisY);
            } else {
                data.setAxisXBottom(null);
                data.setAxisYLeft(null);
            }

            data.setBaseValue(Float.NEGATIVE_INFINITY);
            chart.setLineChartData(data);

        }