代码拉取完成,页面将自动刷新
本项目是基于开源项目OXChart进行ohos化的移植和开发,可以通过项目标签以及github地址(https://github.com/openXu/OXChart )追踪到原项目版本
方法1.
repositories {
flatDir { dirs 'libs' }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
implementation(name: 'OXChart', ext: 'har')
....
}
方法2.
repositories {
maven {
url 'http://106.15.92.248:8081/repository/Releases/'
}
}
dependencies {
implementation 'com.openxu.viewlib.ohos:OXViewLib:1.0.1'
}
<com.openxu.cview.chart.rosechart.NightingaleRoseChart
ohos:id="$+id:roseChartSmall"
ohos:height="200vp"
ohos:width="match_parent"
ohos:top_margin="2vp"/>
roseChartSmall = (NightingaleRoseChart)findComponentById(ResourceTable.Id_roseChartSmall);
roseChartSmall.setShowChartLable(true); //是否在图表上显示指示lable
roseChartSmall.setShowChartNum(false); //是否在图表上显示指示num
roseChartSmall.setShowNumTouched(false); //点击显示数量
roseChartSmall.setShowRightNum(true); //右侧显示数量
roseList.add(new RoseBean(10, "数据1"));
roseList.add(new RoseBean(13, "数据2"));
roseList.add(new RoseBean(31, "数据3"));
roseList.add(new RoseBean(8, "数据4"));
roseList.add(new RoseBean(21, "数据5"));
//参数1:数据对象class, 参数2:数量属性字段名称, 参数3:名称属性字段名称, 参数4:数据集合
roseChartSmall.setData(RoseBean.class, "count", "ClassName", roseList);
roseChartSmall.setLoading(false);//是否正在加载,数据加载完毕后置为false
<com.openxu.cview.chart.piechart.PieChartLayout
ohos:id="$+id:pieChart2"
ohos:height="140vp"
ohos:width="match_parent"
ohos:alignment="vertical_center"
ohos:background_element="#ffffff"
ohos:orientation="horizontal"
ohos:right_padding="10vp"
ohos:top_margin="15vp">
<com.openxu.cview.chart.piechart.PieChart
ohos:height="match_parent"
ohos:width="0vp"
ohos:weight="2"/>
<com.openxu.cview.chart.piechart.PieChartLableView
ohos:height="match_parent"
ohos:width="0vp"
ohos:weight="1"/>
</com.openxu.cview.chart.piechart.PieChartLayout>
pieChart2 = (PieChartLayout)findComponentById(ResourceTable.Id_pieChart2);
pieChart2.setRingWidth(DensityUtil.dip2px(this, 20));
pieChart2.setTagModul(PieChartLayout.TAG_MODUL.MODUL_LABLE); //在lable后面显示tag
pieChart2.setDebug(false);
pieChart2.setLoading(true);
//请求数据
datalist.clear();
datalist.add(new PieBean(20, "IT"));
datalist.add(new PieBean(10, "销售"));
datalist.add(new PieBean(30, "金融"));
datalist.add(new PieBean(8, "林木业"));
datalist.add(new PieBean(15, "制造"));
datalist.add(new PieBean(15, "农业"));
pieChart2.setLoading(false);
pieChart2.setChartData(PieBean.class, "Numner", "Name",datalist ,null);
<com.openxu.cview.chart.ProgressPieChart
ohos:id="$+id:chart2"
ohos:height="200vp"
ohos:width="200vp"
ohos:top_margin="10vp"/>
lables = new ArrayList<>();
lables.add(new ChartLable("60.0%",
DensityUtil.sp2px(this, 12), Color.getIntColor("#ff0000")));
chart2 = (ProgressPieChart)findComponentById(ResourceTable.Id_chart2);
chart2.setProSize(DensityUtil.dip2px(this, 20)); //圆环宽度
chart2.setDebug(false);
chart2.setLoading(false);
chart2.setProColor(Color.getIntColor("#F28D02")); //进度颜色
chart2.setData(100, 60, lables);
<com.openxu.cview.chart.barchart.BarVerticalChart
ohos:id="$+id:chart1"
ohos:height="250vp"
ohos:width="360vp"
ohos:background_element="#ffffff"
ohos:padding="10vp"/>
chart1 = (BarVerticalChart)findComponentById(ResourceTable.Id_chart1);
chart1.setLoading(true);
chart1.setDebug(false);
chart1.setBarNum(1);
chart1.setBarColor(new int[]{Color.getIntColor("#5F93E7")});
//X轴
List<String> strXList = new ArrayList<>();
//柱状图数据
List<List<BarBean>> dataList = new ArrayList<>();
for(int i = 0; i<5; i++){
//此集合为柱状图上一条数据,集合中包含几个实体就是几个柱子
List<BarBean> list = new ArrayList<>();
list.add(new BarBean(random.nextInt(10), "接入系统"));
dataList.add(list);
strXList.add((i+1)+"月");
}
chart1.setLoading(false);
chart1.setData(dataList, strXList);
<com.openxu.cview.chart.barchart.BarHorizontalChart
ohos:id="$+id:chart1"
ohos:height="250vp"
ohos:width="360vp"
ohos:background_element="#ffffff"
ohos:padding="10vp"
ohos:top_margin="20vp"/>
chart1 = (BarHorizontalChart)findComponentById(ResourceTable.Id_chart1);
chart1.setBarSpace(DensityUtil.dip2px(this, 1)); //双柱间距
chart1.setBarItemSpace(DensityUtil.dip2px(this, 20)); //柱间距
chart1.setDebug(false);
chart1.setBarNum(3);
chart1.setBarColor(new int[]{Color.getIntColor("#5F93E7"),Color.getIntColor("#F28D02")});
//X轴
List<String> strXList = new ArrayList<>();
//柱状图数据
List<List<BarBean>> dataList = new ArrayList<>();
for(int i = 0; i<100; i++){
//此集合为柱状图上一条数据,集合中包含几个实体就是几个柱子
List<BarBean> list = new ArrayList<>();
list.add(new BarBean(random.nextInt(30), "lable1"));
list.add(new BarBean(random.nextInt(20), "lable2"));
dataList.add(list);
strXList.add((i+1)+"月");
}
chart1.setLoading(false);
chart1.setData(dataList, strXList);
<com.openxu.cview.xmstock.LinesLableChart
ohos:id="$+id:weightLableChart"
ohos:left_padding="12vp"
ohos:right_padding="12vp"
ohos:bottom_padding="10vp"
ohos:width="match_parent"
ohos:height="60vp" />
<com.openxu.cview.xmstock.LinesChart
ohos:id="$+id:weightLinesChart"
ohos:left_padding="12vp"
ohos:right_padding="12vp"
ohos:bottom_padding="10vp"
ohos:width="match_parent"
ohos:height="200vp" />
weightLableChart = (LinesLableChart) findComponentById(ResourceTable.Id_weightLableChart);
weightLinesChart = (LinesChart) findComponentById(ResourceTable.Id_weightLinesChart);
int[] weightLineColor = new int[]{Color.getIntColor("#dd1d12"),
Color.getIntColor("#fec52e"),
Color.getIntColor("#1e5bac"),
Color.getIntColor("#20b1dd")};
weightLableChart.setLineColor(weightLineColor);
//设置数据为百分比
weightLinesChart.setyMarkType(LinesChart.YMARK_TYPE.PERCENTAGE);
weightLinesChart.setLineColor(weightLineColor);
weightLableChart.setLoading(false);
final String[] weightLables = new String[]{"沪深300","中小板" , "上证指数", "深证指数"};
weightLableChart.setColumnNum(2);
weightLableChart.setData(weightLables, "03-13 15:00");
weightLinesChart.setLoading(false);
weightLinesChart.setOnFocusChangeListener(new LinesChart.OnFocusChangeListener() {
@Override
public void onfocus(FocusInfo focusInfo) {
List<DataPoint> datas = focusInfo.getFocusData();
String[] newWeightLables = new String[4];
for(int i = 0; i<weightLables.length ; i++){
newWeightLables[i] = weightLables[i]+ " "+
(i>datas.size()-1?"0":NumberFormatUtil.formattedDecimalToPercentage(datas.get(i).getValueY()));
}
weightLableChart.setData(newWeightLables, "03-13 15:00");
}
});
weightLinesChart.setData(data.getWeight().getWeight_line(), null);
<com.openxu.cview.xmstock20191205.NorthSouthChart
ohos:id="$+id:chart"
ohos:height="230vp"
ohos:width="match_parent"
ohos:background_element="#fb000000"
ohos:bottom_padding="10vp"
ohos:left_padding="12vp"
ohos:right_padding="12vp"
ohos:top_padding="10vp"/>
chart.setLoading(false);
chart.setChartType(type);
//北向资金
if(type == NorthSouthChart.ChartType.TYPE_T_NORTH || type == NorthSouthChart.ChartType.TYPE_DW_NORTH){
chart.setFocusLableArray(new String[]{"时间", "净流入金额", "上证指数价格", "上证指数跌涨幅"});
//南向资金
}else if(type == NorthSouthChart.ChartType.TYPE_T_SOUTH || type == NorthSouthChart.ChartType.TYPE_DW_SOUTH){
chart.setFocusLableArray(new String[]{"时间", "净流入金额", "恒生指数价格", "恒生指数跌涨幅"});
}
//今日流向
if(type == NorthSouthChart.ChartType.TYPE_T_NORTH || type == NorthSouthChart.ChartType.TYPE_T_SOUTH){
chart.setUpDownColor(new int[]{Color.getIntColor("#FC4B4B"),
Color.getIntColor("#1DAA3E")}); //涨跌颜色(红绿)
//lable 和 color必须按照后台返回数据的顺序设置,比如["0930","1.0亿元","26300.510","+0.91%"] 金额在前,指数在后
chart.setlableColor(new int[]{Color.getIntColor("#DC1010"), Color.getIntColor("#FEB271")});
chart.setYMARK_NUM(5);
// 历史每日每周
}else if(type == NorthSouthChart.ChartType.TYPE_DW_NORTH || type == NorthSouthChart.ChartType.TYPE_DW_SOUTH){
data = new ZSONReader(new StringReader(Constacts.dataMap.get("north-d"))).read(NorthSouth.class);
chart.setlableColor(new int[]{Color.getIntColor("#FC4B4B"),
Color.getIntColor("#1DAA3E"),
Color.getIntColor("#C9D0DC")});
chart.setUpDownColor(new int[]{Color.getIntColor("#FC4B4B"),
Color.getIntColor("#1DAA3E")});
chart.setYMARK_NUM(5);
chart.setXMARK_NUM(4);
}
/**今日流向数据结构一样,历史日周数据结构一样*/
if(type == NorthSouthChart.ChartType.TYPE_T_NORTH){ //北向资金今日流向
chart.setlableArray(new String[]{"总资金净流入", "上证指数价格"});
chart.setLableX(new String[]{"9:30", "11:30/13:00", "15:00"});
}else if(type == NorthSouthChart.ChartType.TYPE_T_SOUTH){ //南向资金今日流向
chart.setlableArray(new String[]{"总资金净流入", "恒生指数价格"});
chart.setLableX(new String[]{"9:30", "12:00/13:00", "16:00"});
} else if(type == NorthSouthChart.ChartType.TYPE_DW_NORTH){ //北向资金 历史每日/周流向
chart.setlableArray(new String[]{"净流入金额", "净流出金额", "上证指数价格"});
} else if(type == NorthSouthChart.ChartType.TYPE_DW_SOUTH){ //南向资金 历史每日/周流向
chart.setlableArray(new String[]{"净流入金额", "净流出金额", "恒生指数价格"});
}
chart.setData(data.getData());
chart.refresh();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。