gpt4 book ai didi

android - 从图表引擎 Android 中删除标题、标签、图例

转载 作者:行者123 更新时间:2023-11-29 14:49:48 25 4
gpt4 key购买 nike

我正在尝试使用 android 中的图表引擎库绘制图表(如下图所示)。

DESIRED_CHART.png

enter image description here

这是我的收获

当前图表.png enter image description here

绘制代码如下

private void drawChart(){
int[] x = { 1,2,3,4,5,6,7,8 };
int[] happyness = { 5,2,4,1,0,4,5,0};
int[] energy = { 5,4,3,1,4,3,5,0};
int[] strenth = { 2,0,1,3,2,4,3,0};
int[] endurance = { 0,2,1,4,3,5,2,0};

// Creating an XYSeries for Income
XYSeries happynessSeries = new XYSeries("Happyness");
// Creating an XYSeries for Income
XYSeries energySeries = new XYSeries("Energy");
// Adding data to Income and Expense Series
XYSeries strenthSeries = new XYSeries("Strenth");
XYSeries enduranceSeries = new XYSeries("Endurance");

for(int i=0;i<x.length;i++){
happynessSeries.add(x[i], happyness[i]);
energySeries.add(x[i],energy[i]);
strenthSeries.add(x[i],strenth[i]);
enduranceSeries.add(x[i],endurance[i]);
}

// Creating a dataset to hold each series
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
// Adding Income Series to the dataset
dataset.addSeries(happynessSeries);
// Adding Expense Series to dataset
dataset.addSeries(energySeries);
dataset.addSeries(strenthSeries);
dataset.addSeries(enduranceSeries);


// Creating XYSeriesRenderer to customize incomeSeries
XYSeriesRenderer happynessRenderer = new XYSeriesRenderer();
happynessRenderer.setColor(Color.parseColor("#f4ed21"));//chart border color
happynessRenderer.setPointStyle(PointStyle.CIRCLE);
happynessRenderer.setFillPoints(true);
happynessRenderer.setLineWidth(2);
happynessRenderer.setDisplayChartValues(true);
happynessRenderer.setFillBelowLine(true);
happynessRenderer.setFillBelowLineColor(Color.parseColor("#bbf4ed21"));

// Creating XYSeriesRenderer to customize expenseSeries
XYSeriesRenderer energyRenderer = new XYSeriesRenderer();
energyRenderer.setColor(Color.parseColor("#20bff2"));
energyRenderer.setPointStyle(PointStyle.CIRCLE);
energyRenderer.setFillPoints(true);
energyRenderer.setLineWidth(2);
energyRenderer.setDisplayChartValues(true);
energyRenderer.setFillBelowLine(true);
energyRenderer.setFillBelowLineColor(Color.parseColor("#bb20bff2"));

// strenth
XYSeriesRenderer strenthRenderer = new XYSeriesRenderer();
strenthRenderer.setColor(Color.parseColor("#f97b1d"));
strenthRenderer.setPointStyle(PointStyle.CIRCLE);
strenthRenderer.setFillPoints(true);
strenthRenderer.setLineWidth(2);
strenthRenderer.setDisplayChartValues(true);
strenthRenderer.setFillBelowLine(true);
strenthRenderer.setFillBelowLineColor(Color.parseColor("#bbf97b1d"));

// endurance
XYSeriesRenderer enduranceRenderer = new XYSeriesRenderer();
enduranceRenderer.setColor(Color.parseColor("#c68c4d"));
enduranceRenderer.setPointStyle(PointStyle.CIRCLE);
enduranceRenderer.setFillPoints(true);
enduranceRenderer.setLineWidth(2);
enduranceRenderer.setDisplayChartValues(true);
enduranceRenderer.setFillBelowLine(true);
enduranceRenderer.setFillBelowLineColor(Color.parseColor("#bbc68c4d"));


// Creating a XYMultipleSeriesRenderer to customize the whole chart
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setXLabels(0);
multiRenderer.setZoomButtonsVisible(true);
for(int i=0;i<x.length;i++){
multiRenderer.addXTextLabel(i+1, mMonth[i]);
}
multiRenderer.setLabelsTextSize(50);
multiRenderer.setYLabels(0);
multiRenderer.setMargins(new int[]{0,0,0,0});

multiRenderer.addSeriesRenderer(happynessRenderer);
multiRenderer.addSeriesRenderer(energyRenderer);
multiRenderer.addSeriesRenderer(strenthRenderer);
multiRenderer.addSeriesRenderer(enduranceRenderer);

multiRenderer.setPanEnabled(false, false);
multiRenderer.setZoomEnabled(false, false);
multiRenderer.setZoomEnabled(false, false);

// Creating an intent to plot line chart using dataset and multipleRenderer
mChart =(GraphicalView) ChartFactory.getLineChartView(getBaseContext(), dataset, multiRenderer);

llChart.addView(mChart);

}

第一个和最后一个 x 轴点值(2 月 3 日星期一和 2 月 9 日星期一)正在削减。我正在努力将这些值显示为 DESIRED_CHART.png

如何去除 X 轴值后面的黑色背景?

最佳答案

改变背景颜色

multiRenderer.setMarginsColor(Color.GREEN);

并给出边距以显示整个 x 轴点值文本

multiRenderer.setMargins(new int[]{0,40,0,40});

隐藏标题

multiRenderer.setChartTitle("");

隐藏图例

multiRenderer.setShowLegend(false);

其中 multiRendererXYMultipleSeriesRenderer

关于android - 从图表引擎 Android 中删除标题、标签、图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22171350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com