AnyChart尝试在一个活动中显示2个折线图。
创始人
2024-08-22 09:30:16
0

要在一个活动中显示两个折线图,可以使用AnyChart库。下面是一个示例代码,演示了如何使用AnyChart库在一个活动中显示两个折线图。

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.anychart.AnyChart;
import com.anychart.AnyChartView;
import com.anychart.chart.common.dataentry.DataEntry;
import com.anychart.chart.common.dataentry.ValueDataEntry;
import com.anychart.charts.Cartesian;
import com.anychart.core.cartesian.series.Line;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // 获取AnyChartView实例
        AnyChartView anyChartView = findViewById(R.id.any_chart_view);
        
        // 创建两个折线图对象
        Cartesian cartesian = AnyChart.line();
        
        // 创建数据点列表
        List data1 = new ArrayList<>();
        data1.add(new ValueDataEntry("Jan", 50));
        data1.add(new ValueDataEntry("Feb", 45));
        data1.add(new ValueDataEntry("Mar", 60));
        
        List data2 = new ArrayList<>();
        data2.add(new ValueDataEntry("Jan", 30));
        data2.add(new ValueDataEntry("Feb", 35));
        data2.add(new ValueDataEntry("Mar", 40));
        
        // 创建折线对象,并添加数据点
        Line line1 = cartesian.line(data1);
        Line line2 = cartesian.line(data2);
        
        // 设置折线图的标题和轴标签
        cartesian.title("Line Chart");
        cartesian.xAxis(0).title("Month");
        cartesian.yAxis(0).title("Value");
        
        // 将折线图添加到AnyChartView中
        anyChartView.setChart(cartesian);
    }
}

在上述代码中,我们首先在布局文件中添加一个AnyChartView,然后在MainActivity中获取AnyChartView实例。接下来,我们创建两个折线图对象,并创建数据点列表。然后,我们创建折线对象,并将数据点添加到折线对象中。最后,我们设置折线图的标题和轴标签,并将折线图添加到AnyChartView中。

请确保在项目的build.gradle文件中添加AnyChart库的依赖项:

implementation 'com.anychart:AnyChart:8.10.0'

这样,你就可以在一个活动中显示两个折线图了。

相关内容

热门资讯

记者揭秘!智星菠萝辅助(透视辅... 记者揭秘!智星菠萝辅助(透视辅助)拱趴大菠萝辅助神器,扑克教程(有挂细节);模式供您选择,了解更新找...
一分钟揭秘!约局吧能能开挂(透... 一分钟揭秘!约局吧能能开挂(透视辅助)hhpoker辅助靠谱,2024新版教程(有挂教学);约局吧能...
透视辅助!wepoker模拟器... 透视辅助!wepoker模拟器哪个好用(脚本)hhpoker辅助挂是真的,科技教程(有挂技巧);囊括...
透视代打!hhpkoer辅助器... 透视代打!hhpkoer辅助器视频(辅助挂)pokemmo脚本辅助,2024新版教程(有挂教程);风...
透视了解!约局吧德州真的有透视... 透视了解!约局吧德州真的有透视挂(透视脚本)德州局HHpoker透视脚本,必胜教程(有挂分析);亲,...
六分钟了解!wepoker挂底... 六分钟了解!wepoker挂底牌(透视)德普之星开辅助,详细教程(有挂解密);德普之星开辅助是一种具...
9分钟了解!wpk私人辅助(透... 9分钟了解!wpk私人辅助(透视)hhpoker德州透视,插件教程(有挂教学);风靡全球的特色经典游...
推荐一款!wepoker究竟有... 推荐一款!wepoker究竟有透视(脚本)哈糖大菠萝开挂,介绍教程(有挂技术);囊括全国各种wepo...
每日必备!wepoker有人用... 每日必备!wepoker有人用过(脚本)wpk有那种辅助,线上教程(有挂规律);wepoker有人用...
玩家必备教程!wejoker私... 玩家必备教程!wejoker私人辅助软件(脚本)哈糖大菠萝可以开挂,可靠技巧(有挂神器)申哈糖大菠萝...