我正在使用AFreeChart进行项目,我无法增加X轴和Y轴的字体

时间:2015-04-20 23:16:17

标签: android linechart

我使用afreechart库在我的应用程序中显示不同类型的图形但是我无法在折线图上增加X和Y轴上的labet大小它没有反映变化...而我无法使该标签文字的大小增加 我的代码在这里



    package com.chartingapp.chartview;

import org.achartengine.GraphicalView;
import org.afree.chart.AFreeChart;
import org.afree.chart.ChartFactory;
import org.afree.chart.LegendItemCollection;
import org.afree.chart.axis.CategoryAxis;
import org.afree.chart.axis.CategoryLabelPositions;
import org.afree.chart.labels.CategoryItemLabelGenerator;
import org.afree.chart.plot.CategoryPlot;
import org.afree.chart.plot.PlotOrientation;
import org.afree.chart.renderer.category.LineAndShapeRenderer;
import org.afree.chart.title.TextTitle;
import org.afree.data.category.CategoryDataset;
import org.afree.data.category.DefaultCategoryDataset;
import org.afree.graphics.SolidColor;
import org.afree.ui.RectangleInsets;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;

import com.chartingapp.ChartView;
import com.chartingapp.R.color;
import com.chartingapp.util.CommonUtil;

public class LineChartView1 extends ChartView {
	private GraphicalView mGraphView;

	private static TextTitle title;
	private static LegendItemCollection items;
	public CommonUtil m_Inst = CommonUtil.getInstance();
	private static float textSize = 30;

	public LineChartView1(Context context, AttributeSet attrs) {
		super(context, attrs);
		final AFreeChart chart = createChart1(createDataset1());
		setChart(chart);
	}

	/***************************** start *********************************/
	private static AFreeChart createChart1(CategoryDataset dataset) {
		AFreeChart chart1 = ChartFactory.createLineChart(CommonUtil.repName,
				"", "Value", dataset, PlotOrientation.VERTICAL, true, true,
				false);

		chart1.setBackgroundPaintType(new SolidColor(Color.WHITE));

		final CategoryPlot plot = chart1.getCategoryPlot();

		plot.setBackgroundPaintType(new SolidColor(Color.WHITE));
		plot.setDomainGridlinePaintType(new SolidColor(Color.BLACK));
		plot.setRangeGridlinePaintType(new SolidColor(Color.BLACK));
		plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
		plot.setDomainCrosshairVisible(true);
		plot.setRangeCrosshairVisible(true);

		LineAndShapeRenderer renderer = new LineAndShapeRenderer();
		renderer.setSeriesShapesVisible(dataset.getRowCount(), true);
		renderer.setBaseItemLabelsVisible(true);

		for (int i = 0; i < dataset.getRowCount(); i++) {
			renderer.setSeriesStroke(i, 2.0f);
			renderer.getSeriesItemLabelPaintType(color.GreenYellow);

			/**********************************************/
			renderer.setSeriesItemLabelGenerator(i,
					new CategoryItemLabelGenerator() {

						@Override
						public String generateRowLabel(CategoryDataset dataset,
								int row) {
							return String.valueOf(dataset.getRowKey(row));
						}

						@Override
						public String generateLabel(CategoryDataset dataset,
								int row, int column) {
							return String.valueOf(dataset.getValue(row, column));
						}

						@Override
						public String generateColumnLabel(
								CategoryDataset dataset, int column) {
							return String.valueOf(dataset.getColumnKey(column));
						}
					});
			/**********************************************/
		}

		plot.setRenderer(renderer);
		plot.setFixedLegendItems(items);
		plot.setWeight(40);
		CategoryAxis domainAxis = plot.getDomainAxis();
		domainAxis.setCategoryLabelPositions(CategoryLabelPositions
				.createUpRotationLabelPositions(Math.PI / 6.0));

		return chart1;

	}

	private CategoryDataset createDataset1() {

		/******************************************************************/
		/****** Argument for Adding Value in dataset *****/
		/* 1st Argument:- Value */
		/* 2nd Argument:- Label for series */
		/* 3rd Argument:- Label for domain axis */
		/***********************************************/
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		/********* If no of row is greater than number of column ***********/

		if (CommonUtil.lineChartType == 0) {
			if (CommonUtil.dataList.get(0).size() > CommonUtil.dataList.size()) {
				for (int i = 0; i < CommonUtil.dataList.size(); i++) {
					for (int j = 0; j < CommonUtil.dataList.get(i).size(); j++) {
						dataset.addValue(Double.valueOf(CommonUtil.dataList
								.get(i).get(j)), String
								.valueOf(CommonUtil.verticalLabel.get(i)),
								String.valueOf(CommonUtil.horizontalLabel
										.get(j)));
						System.out.println("Series:- " + i + "  "
								+ CommonUtil.dataList.get(i).get(j) + "("
								+ CommonUtil.horizontalLabel.get(j) + ")");
					}
				}
			} else {
				for (int i = 0; i < CommonUtil.dataList.get(0).size(); i++) {
					for (int j = 0; j < CommonUtil.dataList.size(); j++) {
						dataset.addValue(Double.valueOf(CommonUtil.dataList
								.get(j).get(i)), String
								.valueOf(CommonUtil.horizontalLabel.get(i)),
								String.valueOf(CommonUtil.verticalLabel.get(j)));
						System.out.println("Series:- " + i + "  "
								+ CommonUtil.dataList.get(j).get(i) + "("
								+ CommonUtil.verticalLabel.get(j) + ")");
					}
				}
			}
		} else {
			for (int i = 0; i < CommonUtil.dataList.size(); i++) {
				for (int j = 0; j < CommonUtil.dataList.get(i).size(); j++) {
					dataset.addValue(
							Double.valueOf(CommonUtil.dataList.get(i).get(j)),
							String.valueOf(CommonUtil.horizontalLabel.get(i)),
							String.valueOf(CommonUtil.verticalLabel.get(j)));
				}
			}
		}
		/******************************************************************/
		return dataset;
	}

	/********************************* end *****************************/
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我猜你正在使用achartengine(来自你的导入),因此你可以改变文字大小:

renderer.setLabelsTextSize(size);
renderer.setLegendHeight(height);

这是一个更灵活的图书馆,请看一下这个答案here