本文整理汇总了Java中com.github.mikephil.charting.charts.Chart类的典型用法代码示例。如果您正苦于以下问题:Java Chart类的具体用法?Java Chart怎么用?Java Chart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Chart类属于com.github.mikephil.charting.charts包,在下文中一共展示了Chart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOffsetForDrawingAtPoint
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
MPPointF offset = getOffset();
mOffset2.x = offset.x;
mOffset2.y = offset.y;
Chart chart = getChartView();
float width = getWidth();
float height = getHeight();
if (posX + mOffset2.x < 0) {
mOffset2.x = - posX;
} else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
mOffset2.x = chart.getWidth() - posX - width;
}
if (posY + mOffset2.y < 0) {
mOffset2.y = - posY;
} else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
mOffset2.y = chart.getHeight() - posY - height;
}
return mOffset2;
}
示例2: getModelType
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
static int getModelType(Chart chart) {
if (chart == null) {
return Model.UNKNOWN_TYPE;
} else {
String type = chart.getTag().toString();
if (HorizontalBarChart.class.getSimpleName().equals(type)) {
Log.d(TAG, "HorizontalBarChart");
return Model.GRAPH_TYPE_BARS;
} else if (BarChart.class.getSimpleName().equals(type)) {
Log.d(TAG, "BarChart");
return Model.GRAPH_TYPE_COLUMNS;
} else {
return Model.UNKNOWN_TYPE;
}
}
}
示例3: generate
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
/**
*
* @return the chart
*/
Chart generate() {
if (data == null) {
return null;
}
try {
String type = data.getJSONObject("chart").getString("type");
Chart chart = null;
switch (type) {
case "column":
chart = generateBarChart();
break;
case "bar":
chart = generateHorizontalBarChart();
break;
default:
break;
}
return chart;
} catch (JSONException e) {
Log.d(TAG, e.getMessage());
return null;
}
}
示例4: setup
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
/**
* 设置字体
*
* @param chart
*/
protected void setup(Chart<?> chart) {
mTy = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
chart.setDescription("");
chart.setNoDataTextDescription("You need to provide data for the chart.");
chart.setTouchEnabled(true);
if (chart instanceof BarLineChartBase) {
BarLineChartBase mChart = (BarLineChartBase) chart;
mChart.setDrawGridBackground(false);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setPinchZoom(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.setTypeface(mTy);
leftAxis.setTextSize(8f);
leftAxis.setTextColor(Color.WHITE);
XAxis xAxis = mChart.getXAxis();
xAxis.setLabelRotationAngle(-50);//设置x轴字体显示角度
xAxis.setTypeface(mTy);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(8f);
xAxis.setTextColor(Color.WHITE);
mChart.getAxisRight().setEnabled(false);
}
}
示例5: prepareLegend
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
/**
* Create a legend based on a dummy chart. The legend
* is used by all charts and is positioned
* across the top of the screen.
* @param data - CombinedData used to generate the legend
*/
private void prepareLegend(final CombinedData data){
//The dummy chart is never shown, but it's legend is.
final CombinedChart dummyChart = (CombinedChart) mRoot.findViewById(R.id.legend);
dummyChart.getPaint(Chart.PAINT_DESCRIPTION).setTextAlign(Paint.Align.CENTER);
dummyChart.getXAxis().setEnabled(false);
dummyChart.getAxisRight().setEnabled(false);
dummyChart.getAxisLeft().setEnabled(false);
final Description description = new Description();
description.setText("");
description.setTextSize(10f);
dummyChart.setDescription(description);
dummyChart.setBackgroundColor(Color.WHITE);
dummyChart.setDrawGridBackground(false);
dummyChart.setData(data);
final Legend l = dummyChart.getLegend();
l.setEnabled(true);
// The positioning of the legend effectively
// hides the dummy chart from view.
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
dummyChart.invalidate();
}
示例6: setDescription
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
@ReactProp(name = "description")
public void setDescription(Chart chart, ReadableMap propMap) {
if (BridgeUtils.validate(propMap, ReadableType.String, "text")) {
chart.setDescription(propMap.getString("text"));
}
if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) {
chart.setDescriptionColor(Color.parseColor(propMap.getString("textColor")));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
chart.setDescriptionTextSize((float) propMap.getDouble("textSize"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "positionX") &&
BridgeUtils.validate(propMap, ReadableType.Number, "positionY")) {
chart.setDescriptionPosition((float) propMap.getDouble("positionX"), (float) propMap.getDouble("positionY"));
}
if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") ||
BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) {
chart.setDescriptionTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily"));
}
}
示例7: setXAxis
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
/**
* xAxis config details: https://github.com/PhilJay/MPAndroidChart/wiki/XAxis
*/
@ReactProp(name = "xAxis")
public void setXAxis(Chart chart, ReadableMap propMap) {
XAxis axis = chart.getXAxis();
setCommonAxisConfig(chart, axis, propMap);
if (BridgeUtils.validate(propMap, ReadableType.Number, "labelsToSkip")) {
axis.setLabelsToSkip(propMap.getInt("labelsToSkip"));
}
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "avoidFirstLastClipping")) {
axis.setAvoidFirstLastClipping(propMap.getBoolean("avoidFirstLastClipping"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBetweenLabels")) {
axis.setSpaceBetweenLabels(propMap.getInt("spaceBetweenLabels"));
}
if (BridgeUtils.validate(propMap, ReadableType.String, "position")) {
axis.setPosition(XAxisPosition.valueOf(propMap.getString("position")));
}
}
示例8: setData
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
private static void setData(Chart barChart, List<Pair<String, Integer>> chartData, String title, Context context) {
ArrayList<BarEntry> yVals = new ArrayList<>();
int count = chartData.size() > 10 ? 10 : chartData.size();
for (int i = 0; i < count; i++) { //10 top states
yVals.add(new BarEntry(i,chartData.get(i).second));
}
BarDataSet barDataSet = new BarDataSet(yVals, title);
int[] colors = new int[]{context.getResources().getColor(R.color.colorChart1),
context.getResources().getColor(R.color.colorChart2),
context.getResources().getColor(R.color.colorChart3),
context.getResources().getColor(R.color.colorChart4),
context.getResources().getColor(R.color.colorChart5)};
barDataSet.setColors(colors);
BarData data = new BarData(barDataSet);
data.setValueTextSize(12f);
barChart.setData(data);
}
示例9: setupLegend
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
protected void setupLegend(Chart chart) {
List<Integer> legendColors = new ArrayList<>(4);
List<String> legendLabels = new ArrayList<>(4);
legendColors.add(akActivity.color);
legendLabels.add(akActivity.label);
legendColors.add(akLightSleep.color);
legendLabels.add(akLightSleep.label);
legendColors.add(akDeepSleep.color);
legendLabels.add(akDeepSleep.label);
legendColors.add(akNotWorn.color);
legendLabels.add(akNotWorn.label);
if (supportsHeartrate(getChartsHost().getDevice())) {
legendColors.add(HEARTRATE_COLOR);
legendLabels.add(HEARTRATE_LABEL);
}
chart.getLegend().setCustom(legendColors, legendLabels);
}
示例10: PieChartCustom
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
public PieChartCustom(PieChart graphical, ArrayList<Entry> entries, String entriesLegend, ArrayList<String> labels, String chartDecription)
{
this.entries = entries;
this.chart = graphical;
this.dataset = new PieDataSet(entries, entriesLegend);
this.data = new PieData(labels, this.dataset);
this.colors = new ArrayList<>();
//chart.setTouchEnabled(false);
this.legend = chart.getLegend();
if(chartDecription!= null)
chart.setDescription(chartDecription);
else chart.setDescription("");
float sum = 0f;
for(int i = 0; i<entries.size(); i++)
{
sum += entries.get(i).getVal();
}
this.chart.setCenterText(String.format("%1$s\n%2$.2f", "Total", sum));
this.chart.setCenterTextSize(16);
Paint text = new Paint();
text.setTextAlign(Paint.Align.CENTER);
this.chart.setPaint(text, Chart.PAINT_CENTER_TEXT);
this.chart.setUsePercentValues(true);
setDefaultChart();
setDefaultLegend();
}
示例11: drawHighlighted
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
Chart chart = mChart.get();
if (chart == null) return;
for (DataRenderer renderer : mRenderers) {
ChartData data = null;
if (renderer instanceof BarChartRenderer)
data = ((BarChartRenderer)renderer).mChart.getBarData();
else if (renderer instanceof LineChartRenderer)
data = ((LineChartRenderer)renderer).mChart.getLineData();
else if (renderer instanceof CandleStickChartRenderer)
data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
else if (renderer instanceof ScatterChartRenderer)
data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
else if (renderer instanceof BubbleChartRenderer)
data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();
int dataIndex = data == null ? -1
: ((CombinedData)chart.getData()).getAllData().indexOf(data);
mHighlightBuffer.clear();
for (Highlight h : indices) {
if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
mHighlightBuffer.add(h);
}
renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
}
}
示例12: getOffsetForDrawingAtPoint
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
MPPointF offset = getOffset();
mOffset2.x = offset.x;
mOffset2.y = offset.y;
Chart chart = getChartView();
float width = mSize.width;
float height = mSize.height;
if (width == 0.f && mDrawable != null) {
width = mDrawable.getIntrinsicWidth();
}
if (height == 0.f && mDrawable != null) {
height = mDrawable.getIntrinsicHeight();
}
if (posX + mOffset2.x < 0) {
mOffset2.x = - posX;
} else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
mOffset2.x = chart.getWidth() - posX - width;
}
if (posY + mOffset2.y < 0) {
mOffset2.y = - posY;
} else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
mOffset2.y = chart.getHeight() - posY - height;
}
return mOffset2;
}
示例13: onDrawFinished
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
/** callback when a DataSet has been drawn (when lifting the finger) */
@Override
public void onDrawFinished(DataSet<?> dataSet) {
Log.i(Chart.LOG_TAG, "DataSet drawn. " + dataSet.toSimpleString());
// prepare the legend again
mChart.getLegendRenderer().computeLegend(mChart.getData());
}
示例14: setup
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
protected void setup(Chart<?> chart) {
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
// no description text
chart.getDescription().setEnabled(false);
// enable touch gestures
chart.setTouchEnabled(true);
if (chart instanceof BarLineChartBase) {
BarLineChartBase mChart = (BarLineChartBase) chart;
mChart.setDrawGridBackground(false);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.setTypeface(mTf);
leftAxis.setTextSize(8f);
leftAxis.setTextColor(Color.DKGRAY);
leftAxis.setValueFormatter(new PercentFormatter());
XAxis xAxis = mChart.getXAxis();
xAxis.setTypeface(mTf);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(8f);
xAxis.setTextColor(Color.DKGRAY);
mChart.getAxisRight().setEnabled(false);
}
}
示例15: getOffsetForDrawingAtPoint
import com.github.mikephil.charting.charts.Chart; //导入依赖的package包/类
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
MPPointF offset = getOffset();
offset.x = max(offset.x, - posX);
offset.y = max(offset.y, - posY);
Chart chart = getChartView();
if (chart != null) {
offset.x = min(offset.x, chart.getWidth() - posX - getWidth());
offset.y = min(offset.y, chart.getHeight() - posY - getHeight());
}
return offset;
}