android天气温度折线图 天气预报温度曲线

您所在的位置:网站首页 关于天气的统计图怎么画的 android天气温度折线图 天气预报温度曲线

android天气温度折线图 天气预报温度曲线

2024-07-16 02:20| 来源: 网络整理| 查看: 265

android天气温度折线图 天气预报温度曲线 转载

mob6454cc7d4112 2023-07-27 13:50:53

文章标签 android天气温度折线图 XCL-Charts 图表 List ide 文章分类 Android 移动开发

最近在开发一款天气app,有一个功能是显示当天24小时每三个小时的气温状况,这个功能无疑要用图表来实现最好了。所以在github上找到一个国人开发的图表库,XCL-Charts。 先上效果图:

android天气温度折线图 天气预报温度曲线_XCL-Charts

首先创建一个SplineChartView继承自GraphicalView,再主要实现三个方法

第一个是关于图表的渲染

private void chartRender()

{

try {

//设置绘图区默认缩进px值,留置空间显示Axis,Axistitle.... int [] ltrb = getBarLnDefaultSpadding(); chart.setPadding(ltrb[0] + DensityUtil.dip2px(this.getContext(), 20), ltrb[1], ltrb[2]+DensityUtil.dip2px(this.getContext(), 30), ltrb[3]); //显示边框 chart.showRoundBorder(); //数据源 chart.setCategories(labels); chart.setDataSource(chartData); // chart.setCustomLines(mCustomLineDataset); //坐标系 //数据轴最大值 chart.getDataAxis().setAxisMax(40); chart.getDataAxis().setAxisMin(-40); //数据轴刻度间隔 chart.getDataAxis().setAxisSteps(2); //标签轴最大值 chart.setCategoryAxisMax(5); //标签轴最小值 chart.setCategoryAxisMin(0); //背景网格 PlotGrid plot = chart.getPlotGrid(); plot.hideHorizontalLines(); plot.hideVerticalLines(); chart.getPlotArea().setBackgroundColor(true, Color.GRAY); chart.getCategoryAxis().getAxisPaint().setColor(Color.WHITE); chart.getCategoryAxis().getAxisPaint().setTextSize(6); chart.getCategoryAxis().hideTickMarks(); chart.getCategoryAxis().getTickLabelPaint().setColor(Color.WHITE); chart.getCategoryAxis().getTickLabelPaint().setFakeBoldText(true); chart.getCategoryAxis().setTickLabelMargin(25); chart.getCategoryAxis().getTickLabelPaint().setTextSize(25); //不使用精确计算,忽略Java计算误差,提高性能 chart.disableHighPrecision(); chart.disablePanMode(); chart.hideBorder(); chart.getPlotLegend().hide(); chart.getDataAxis().hide(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Log.e("tag", e.toString()); } }

其中chart.getPlotArea().setBackgroundColor(true, Color.GRAY);是设置图表绘制区的颜色,chart.getDataAxis().setAxisMax(40);在我的app中表示能显示的最高温度是40摄氏度,chart.getDataAxis().setAxisMin(-40);表示能显示的最低温度是-40摄氏度。

第二个和第三个都是绑定数据的。public void setChartDataSet(List temps) { //线1的数据集 List linePoint1 = new ArrayList(); linePoint1.add(new PointD(0d, Double.parseDouble(temps.get(0)))); linePoint1.add(new PointD(1d, Double.parseDouble(temps.get(1)))); linePoint1.add(new PointD(2d, Double.parseDouble(temps.get(2)))); linePoint1.add(new PointD(3d, Double.parseDouble(temps.get(3)))); linePoint1.add(new PointD(4d, Double.parseDouble(temps.get(4)))); linePoint1.add(new PointD(5d, Double.parseDouble(temps.get(5))));SplineData dataSeries1 = new SplineData("Go",linePoint1, Color.WHITE ); //把线弄细点 dataSeries1.getLinePaint().setStrokeWidth(3); dataSeries1.setLineStyle(XEnum.LineStyle.DASH); dataSeries1.setLabelVisible(false); dataSeries1.setDotStyle(XEnum.DotStyle.RING); dataSeries1.getDotPaint().setColor(getResources().getColor(R.color.white)); dataSeries1.getPlotLine().getPlotDot().setRingInnerColor(getResources().getColor(R.color.grey)); chartData.add(dataSeries1); this.invalidate(); } public void setChartLabels(List weather){ String[] times={"20:00\n","23:00\n","2:00\n","5:00\n","8:00\n","11:00\n"}; for(int i=0;i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3