ChartsOrg / ChartsOrg/Charts

line data set position center in combine chart MPAndroidChart

Open
#5,214 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

ISSUE IS HOW TO SET POSISTION OF LINE DATA(PRICE DATA) in CENTER
IF IS SET
YAxis leftAxis = combinedChart.getAxisLeft();

it move complete chart to Center

Legend legend = combinedChart.getLegend();
legend.setEnabled(true);
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);

// Define custom legend entries for red, green, blue, and purple boxes
LegendEntry redEntry = new LegendEntry();
redEntry.formColor = getResources().getColor(android.R.color.holo_red_dark);
redEntry.label = "Volume"; // Label for red box

LegendEntry greenEntry = new LegendEntry();
greenEntry.formColor = getResources().getColor(android.R.color.holo_green_dark);
greenEntry.label = "Volume"; // Label for green box

LegendEntry blueEntry = new LegendEntry();
blueEntry.formColor = getResources().getColor(android.R.color.holo_blue_dark);
blueEntry.label = "OI"; // Label for blue box

LegendEntry blackEntry = new LegendEntry();
blackEntry.formColor = getResources().getColor(android.R.color.holo_purple);
blackEntry.label = "Price"; // Label for purple box

legend.setCustom(Arrays.asList(redEntry, greenEntry, blueEntry, blackEntry));
combinedChart.getDescription().setEnabled(false);

// Optional: Add animations and other customizations
combinedChart.animateY(1000); // Animate vertically over 1000ms

CombinedData combinedData = new CombinedData();

// Get BarData (Volume) and assign it to the left Y-Axis
BarData volumeData = getVolume(modelclassIOdata);
volumeData.setBarWidth(0.9f); // Set bar width for better visualization
combinedData.setData(volumeData); // Adding bar data to combined data

// Get LineData (Price) and assign it to the right Y-Axis
LineData priceData = getPrice(modelclassIOdata);
YAxis priceYAxis = new YAxis();
priceYAxis.setAxisMinimum(miniprice - 50); // Adjust range to show the price line in the middle
priceYAxis.setAxisMaximum(maxprice + 50); // Set the range for price chart

// Get LineData (Open Interest) and assign it to the right Y-Axis
LineData oiData = getOI(modelclassIOdata);

LineData lineData = new LineData();

// Add both datasets to the lineData
lineData.addDataSet(priceData.getDataSetByIndex(0)); // Price data set
lineData.addDataSet(oiData.getDataSetByIndex(0)); // Open Interest data set

// Set the combined LineData to combinedData
combinedData.setData(lineData);

priceData.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
return String.format(Locale.US, "%.5f", value); // Ensure high precision
}
});

// Update the CombinedChart with the new data
combinedChart.setData(combinedData);

// Refresh the chart to reflect the changes
combinedChart.invalidate();

price data can contain value in -15222 , .2000 , 15000 for different pairs

Contributor guide

Open the contributing guide

Research direction

No repository file, test, or entry point is identified in the issue. Start by reproducing the CombinedChart setup with price values ranging from -15222 to 15000, then read the axis and dataset positioning behavior to determine whether the requested centering is supported and what a completed result should look like.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
data-visualization, mobile-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.