My stacked bar chart in MPAndroidChart works very well but I'm trying to remove or edit the values inside the bars. But I can't find any code which makes sense to modify.
I don't think that my code is very helpful, but here it is...
private void initStackedBarChartStuff() {
mMonths = dfs.getShortMonths();
mChart = (BarChart) mContext.findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.setDescription("");
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(30);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(false);
// change the position of the y-labels
YAxis yLabels = mChart.getAxisLeft();
yLabels.setValueFormatter(new MyYAxisValueFormatter());
mChart.getAxisRight().setEnabled(false);
mChart.getAxisLeft().setEnabled(false);
XAxis xLabels = mChart.getXAxis();
xLabels.setPosition(XAxis.XAxisPosition.TOP);
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.BELOW_CHART_RIGHT);
l.setFormSize(8f);
l.setFormToTextSpace(4f);
l.setXEntrySpace(6f);
// mChart.setDrawLegend(false);
}
fill the stackedBarChart
private void fillStackedBarChart(Vector drawingData, Vector drawingIntervall) {
if (drawingData == null || drawingData == null)
return;
int anzBdata = dataSizes[1];
int intervall = globalIntervall;
ArrayList<String> xVals = new ArrayList<String>();
// Strings über die Blöcke schreiben ###########################################
{
long zeit = 0;
String[] months = new String[12];
String[] days = new String[7];
boolean einmal = true;
for (int i = 0; i < drawingIntervall.size(); i++)
zeit += ((Long) drawingIntervall.get(i)).longValue();
if (bigData) // > 2 Jahre
months = null;
else if (zeit > 31623000) // > 1 Jahre
months = dfs.getShortMonths();
else
months = dfs.getMonths();
days = dfs.getWeekdays();
for (int i = 0; i < drawingData.size(); i++) {
long[] pack = (long[]) drawingData.get(i);
String s = "";
// Sonderfall !! In Monatsansicht den Monat dazu schreiben
if ((einmal) && (intervall == 2)) {
if (etStart.getText().toString().trim().startsWith("01.")) {
Calendar calE = convStringToDate(etEnd.getText().toString().trim(), true, true);
int jahr = calE.get(Calendar.YEAR);
int monat = calE.get(Calendar.MONTH);
Calendar calX = myGetInstance();
calX.set(Calendar.YEAR, jahr);
calX.set(Calendar.MONTH, monat);
calX = getLastDayOfMonth(calX);
if (calE.getTimeInMillis() == calX.getTimeInMillis()) {
einmal = false;
s = months[calE.get(Calendar.MONTH)];
}
}
}
switch (intervall) {
case 0:
s += df.format(convMilliToDate(pack[0] * 1000, false, false).getTime());
break;
case 1:
s += convMilliToString(pack[0] * 1000);
break;
case 2:
s += "KW " + convMilliToDate(pack[0] * 1000, false, false).get(Calendar.WEEK_OF_YEAR);
break;
case 3:
if (bigData)
s += convMilliToDate(pack[0] * 1000, false, false).get(Calendar.YEAR) + "";
else
s += months[convMilliToDate(pack[0] * 1000, false, false).get(Calendar.MONTH)];
break;
}
xVals.add(s);
}
}
// nun alle Balken/Blöcke zeichnen ##########################################
{
// 1 Y-Wert entspricht z.B. 1 Tag, o. 1 Woche,... jeder Y-Wert hat so viele floats wie B-Daten vorhanden sind ###########################################
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < drawingData.size(); i++) {
long[] pack = (long[]) drawingData.get(i);
long intervallSek = ((Long) drawingIntervall.get(i)).longValue() + 1;
long pastSek = 0;
float[] f = new float[anzBdata + 1];
int b = 0;
for (int j = 0; j < pack.length; j++) {
if ((j >= dataSizes[0]) && (j <= (anzBdata - 1 + dataSizes[0]))) {
f[b++] = pack[j];
pastSek += pack[j];
}
}
f[b++] = intervallSek - pastSek; // zeichnet einen Block indem "keine Daten" aufgezeichnet wurden. (wenn Maschine ohne Strom o.ä.)
yVals1.add(new BarEntry(f, i));
}
// BarDataSet set1 = new BarDataSet(yVals1, "Statistics Business Data");
BarDataSet set1 = new BarDataSet(yVals1, "");
set1.setColors(getColors());
set1.setStackLabels(barChartLegend);
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);
data.setValueFormatter(new MyValueFormatter());
mChart.setData(data);
mChart.invalidate();
}
}
This solution is not really pretty, may somone else find a better one...
The class BarChart extends from BarLineChartBase. There is a line in BarLineChartBase which can be annotated or removed to get the desired solution.
mRenderer.drawValues(canvas);
There are basically two ways:
Use the ValueFormatter to custom format your values (edit or remove)
Use dataSet.setDrawValues(false) to completely remove all values
Related
I have a tensorflow lite model which use,
input is {1,320,320,3}
output array dataType is {FLOAT32,FLOAT32,INT32}.
Interpreter#runForMultipleInputsOutputs crashed when resized the input to {1,224,320,3}.
My tensorflow lite version:
implementation('org.tensorflow:tensorflow-lite:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-support:0.0.0-nightly') { changing = true }
Create the input tensor. Prepare the output tensor:
inputImageBuffer = new TensorImage(imageDataType);
outputArr = new TensorBuffer[tflite.getOutputTensorCount()];
resizeOutputArr = new TensorBuffer[tflite.getOutputTensorCount()];
for (int i = 0, count = tflite.getOutputTensorCount(); i < count; i++) {
DataType pDataType = tflite.getOutputTensor(i).dataType();
if (pDataType == DataType.INT32) pDataType = DataType.FLOAT32;
outputArr[i] = TensorBuffer.createFixedSize(i == 0 ? new int[]{imageSizeY, imageSizeX} : new int[]{imageSizeX}, pDataType);
resizeOutputArr[i] = TensorBuffer.createDynamic(pDataType);
}
Resize the input imagebuffer
// Loads bitmap into a TensorImage.
inputImageBuffer.load(bitmap);
float sc = bitmap.getWidth() / 320.0f;
int scaleWid = Math.round(bitmap.getWidth() / sc);
int scaleHei = Math.round(bitmap.getHeight() / sc);
imageSizeY = scaleHei / 32 * 32;
// Creates processor for the TensorImage.
int numRotation = sensorOrientation / 90;
this.processor =
new ImageProcessor.Builder()
.add(new ResizeOp(scaleHei, scaleWid, ResizeOp.ResizeMethod.NEAREST_NEIGHBOR))
.add(new ResizeWithCropOrPadOp(imageSizeY, imageSizeX))
.add(new Rot90Op(numRotation))
.add(new GrayOp(imageSizeY, imageSizeX))
.add(getPreprocessNormalizeOp())
.build();
processor.process(inputImageBuffer);
Run:
int imageTensorIndex = 0;
int[] imageShape = tflite.getInputTensor(imageTensorIndex).shape(); // {1, height, width, 3}
if (imageSizeY != imageShape[1] || imageShape[1] == 0) { // imageSizeY changed
tflite.resizeInput(imageTensorIndex, new int[]{1, imageSizeY, imageSizeX, 3}); //resize inputTensor
for (int i = 0, count = tflite.getOutputTensorCount(); i < count; i++) { //recreate outputTensor
DataType pDataType = tflite.getOutputTensor(i).dataType();
if (pDataType == DataType.INT32) pDataType = DataType.FLOAT32;
outputArr[i] = TensorBuffer.createFixedSize(i == 0 ? new int[]{imageSizeY, imageSizeX} : new int[]{imageSizeX}, pDataType);
}
}
Map<Integer, Object> outputMap = new HashMap<>();
for (int i = 0, cnt = outputArr.length; i < cnt; i++) { //rewind outputBuffer
outputMap.put(i, outputArr[i].getBuffer().rewind());
resizeOutputArr[i].getBuffer().rewind();
}
try {
tflite.runForMultipleInputsOutputs(new Object[]{inputImageBuffer.getBuffer()}, outputMap);
} catch (IllegalArgumentException e) {
e.printStackTrace();
return null;
}
for (int i = 0, count = tflite.getOutputTensorCount(); i < count; i++) { //resize outputArr with new shape
int[] shape = tflite.getOutputTensor(i).shape();
outputArr[i].getBuffer().limit(computeFlatSize(shape) * DataType.FLOAT32.byteSize());
resizeOutputArr[i].loadBuffer(outputArr[i].getBuffer(), shape);
outputArr[i].getBuffer().clear();
if (i == count - 1 && shape != null && shape[0] <= 0) return null;
}
return resizeOutputArr;
protected static int computeFlatSize(#NonNull int[] shape) {
SupportPreconditions.checkNotNull(shape, "Shape cannot be null.");
int prod = 1;
for (int i = 0; i < shape.length; ++i) {
prod *= shape[i];
}
return prod;
}
I got blew Exception when there is no recognized object in the Bitmap:
W: java.lang.IllegalArgumentException: Internal error: Tensor hasn't been allocated.
W: at org.tensorflow.lite.Tensor.buffer(Native Method)
W: at org.tensorflow.lite.Tensor.buffer(Tensor.java:493)
W: at org.tensorflow.lite.Tensor.copyTo(Tensor.java:264)
W: at org.tensorflow.lite.Tensor.copyTo(Tensor.java:254)
W: at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:170)
W: at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:343)
W: at com.fotric.irdetector.qf.tflite.Classifier.recognizeImage(Classifier.java:283)
This exception reduces the recognition performance, Someone help me, thanks!!!
This is the code for this issue for you to check if there is any problem in the code.
Now the problem is when I limit the rows to 45 (this number fits in one page) every row will print in one page.
But, If I don't limit the rows and the row size (approximately 100-200), every row goes to new page in the PDF. The PDF page number goes to approximately equal to row numbers.
I have opened this issue in Boxable's git but it's not active so I came for help here.
Following are the files generated in both conditions:
LimitTemp.pdf
noLimitTemp.pdf
public class CSVtoPDF {
private float marginBetweenYElements = 10;
private float titleFontSize = 18;
private float fontSize = 8;
private float headerFontSize = 12;
private float header1FontSize = 14;
private float header2FontSize = 12;
private float headerCellHeight = 19;
private float dataCellHeight = 12;
private PDFont font = PDType1Font.HELVETICA;
private PDFont headerFont = PDType1Font.TIMES_BOLD;
List filteredData = new ArrayList();
ReportSettings rs = new ReportSettings();
String filePath, destPath, header1, header2, filename;
public CSVtoPDF(List data, Audit audit) throws IOException {
this.filteredData = data;
Date liveDate = new Date();
SimpleDateFormat format= new SimpleDateFormat("YYYY-MM-DD HH:mm:ss");
liveDate = Calendar.getInstance().getTime();
float headerCellHeight = 18;
PDDocument doc = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
//page.setMediaBox(new PDRectangle(PDRectangle.A4.getHeight(),
// PDRectangle.A4.getWidth()));
PDPageContentStream cos = new PDPageContentStream(doc, page);
/* Add page to PDDocument */
doc.addPage(page);
System.out.println("Inside Main csvtopdf");
//Draw Header
Preferences prefs = Preferences.userRoot().node(this.getClass().getName());
try {
String[] keys = prefs.keys();
//destPath = prefs.get("destpath", rs.getDestPath());
//filename = prefs.get("file_name", rs.getFileName());
//header1 = prefs.get("header1", rs.getHeader1());
//header2 = prefs.get("header2", rs.getHeader2());
} catch (BackingStoreException ex) {
System.err.println(ex);
}
header1= "Header 1";
header2= "Header 2";
cos.beginText();
cos.moveTextPositionByAmount(220, 810);
cos.setFont(headerFont, header1FontSize);
cos.drawString(header1);
cos.endText();
cos.beginText();
cos.moveTextPositionByAmount(220, 800);
cos.setFont(headerFont, header2FontSize);
cos.drawString(header2);
cos.endText();
cos.beginText();
cos.moveTextPositionByAmount(220, 790);
cos.setFont(headerFont, headerFontSize);
cos.drawString("Report: Filtered Audit Report");
cos.endText();
//cos.beginText();
// cos.moveTo(200, 30);
//cos.setFont(headerFont, headerFontSize);
// cos.drawString(header2);
//cos.endText();
/* Initialize DataTable */
float margin = 20;
float tableWidth = page.getMediaBox().getWidth() - (2 * margin);
float yStartNewPage = page.getMediaBox().getHeight() - (2 * margin);
float yStart = yStartNewPage;
float bottomMargin = -800;
BaseTable table = new BaseTable(yStart, yStartNewPage,
bottomMargin, tableWidth, margin, doc, page, true, true);
Row<PDPage> dataRow = table.createRow(dataCellHeight);
for (int i = 0; i < data.size() - 1; i++) {
System.out.println(data.get(i));
}
drawTableData(table, dataCellHeight, 20, data, 1,doc,page);
table.draw();
File result;
if (Objects.isNull(destPath)) {
cos.close();
result = new File("temp.pdf");
} else {
result = new File(destPath);
}
System.out.println("befor save result");
doc.save(result);
System.out.println("after save result");
}
public void drawTableData(BaseTable table, float dataCellHeight, float
cellWidth, List<Audit> data, int style,PDDocument doc,PDPage page) {
String s;
Cell<PDPage> cell;
// for (int k = 0; k < data.size(); k++) {
System.out.println("inside drawtable for ");
for (int i = 0; i < data.size(); i++) { // add row
System.out.println("inside drawtable for " + i);
Audit atmp = data.get(i);
//if (i==35) {
// doc.addPage(page);
//}
Row<PDPage> sTableRow = table.createRow(dataCellHeight);
for (int j = 0; j <= 2; j++) { //add cell in the rows
if (j == 0) { // normal cells on right
s = atmp.getTimeStamp();
s = s.replaceAll("^\"|\"$", "");
cell = sTableRow.createCell(cellWidth, s, HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM);
setStyle(style, cell);
//k++;
} else if (j == 1) { //big cells on left
s = atmp.getDiscription();
s = s.replaceAll("^\"|\"$", "");
cell = sTableRow.createCell(cellWidth + 50, s, HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM);
setStyle(style, cell);
// k++;
} else if (j == 2) { //top blank cell
//System.out.println("In j null and 0 " + j);
s = atmp.getUserID();
s = s.replaceAll("^\"|\"$", "");
cell = sTableRow.createCell(cellWidth - 10, s, HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM);
//cell.setBottomBorderStyle(null);
setStyle(style, cell);
//k++;
}
}
table.addHeaderRow(sTableRow);
System.out.println(" row added ");
}
//}
}
public void setStyle(int type, Cell cell) {
// type : 0 as header, 1 as table body
if (type == 0) {
cell.setFont(headerFont);
//cell.setHeight(headerCellHeight);
cell.setFontSize(headerFontSize);
cell.setBottomPadding(3);
} else if (type == 1) {
cell.setTopPadding(1);
cell.setFont(font);
cell.setAlign(HorizontalAlignment.LEFT);
//cell.setHeight(dataCellHeight);
cell.setFontSize(fontSize);
cell.setBottomPadding(1);
}
}
I found a silly problem in my code. I am telling this so that someone else must not repeat this.
I treated every row of the data table as header row. So it went to new page.
To be specific. In the function drawTableData I removed table.addHeaderRow(sTableRow)
I'm using Apache POI and I am running into a weird problem. I can auto-size my rows, but only if there are no merged cells in that row. Here's an example:
new FileOutputStream('test.xlsx').withStream { OutputStream os ->
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
CellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
Row row = sheet.createRow(0); row.setRowStyle(wrapStyle);
Cell cell = row.createCell(0); cell.setCellStyle(wrapStyle);
cell.setCellValue("Very long text that needs to be wrapped")
cell = row.createCell(1); cell.setCellStyle(wrapStyle);
cell.setCellValue("Short text");
cell = row.createCell(2); cell.setCellStyle(wrapStyle);
cell.setCellValue("");
// These two lines break row auto-height!
//
CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 1, 2);
sheet.addMergedRegion(cellRangeAddress);
workbook.write(os);
}
This code generates the following document:
However, as soon as I comment out the lines that merge the two cells, the output looks like this:
Is this a bug? Does anyone know of a workaround?
By using the last part from Val Blant I've did something that's easier to use, and yet much complex.
Please be aware that there is a single line of code that adds one additional line to the cell height-wise, for personal reasons. If you do not wish that, please remove it. Also feel free to change it to a non-static, I've had to use static methods due to the company I'm working for making the specific class static.
PS: It's my first post on stackoverflow, please be gentle. :)
Solution:
public static Boolean isCellMerged(Cell cell) {
Sheet sheet = cell.getSheet();
for (CellRangeAddress mergedRegionRange : sheet.getMergedRegions()) {
Integer cellColumn = cell.getColumnIndex();
Integer cellRow = cell.getRowIndex();
if (mergedRegionRange.containsColumn(cellColumn) && mergedRegionRange.containsRow(cellRow)) {
return true;
}
}
return false;
}
public static List<List<Cell>> getCellsInRowsInsideRegionRange(Cell cell) {
Sheet sheet = cell.getSheet();
List<List<Cell>> mergedRowList = new ArrayList<>();
List<Cell> mergedCellsList = new ArrayList<>();
//Nejdříve musíme zjistit sloučenou sekci dané buňky
for (CellRangeAddress mergedRegionRange : sheet.getMergedRegions()) {
Integer cellColumn = cell.getColumnIndex();
Integer cellRow = cell.getRowIndex();
if (mergedRegionRange.containsColumn(cellColumn) && mergedRegionRange.containsRow(cellRow)) {
//Protože CellRangeAddress nemá moc metod, musíme si pomoci sami a získat z ní buňky a řádky
for (Row row : sheet) {
for (Cell iteratedCell : row) {
Integer iteratedCellColumn = iteratedCell.getColumnIndex();
Integer iteratedCellRow = iteratedCell.getRowIndex();
if (mergedRegionRange.containsColumn(iteratedCellColumn) && mergedRegionRange.containsRow(iteratedCellRow)) {
//Rozdělování jednotlivých řádků
//Není-li řádek bez buněk...
if (!mergedCellsList.isEmpty()) {
//Tak buňku přidáme do Listu buněk...
mergedCellsList.add(iteratedCell);
} else {
//Pokud se jedná o první buňku prvního řádku, tak přidáme rovnou
mergedCellsList.add(iteratedCell);
}
}
}
//Vložíme List buněk daného řádku do Listu řádků
if (!mergedCellsList.isEmpty()) {
mergedRowList.add(mergedCellsList);
}
//A vyresetujeme list buněk (začneme tak nanovo novým řádkem)
mergedCellsList = null;
mergedCellsList = new ArrayList<>();
}
//Vrátíme výsledný List řádků, obsahující Listy buněk ve sloučené sekci.
if (!mergedRowList.isEmpty()) {
return mergedRowList;
} else {
return null;
}
}
}
return null;
}
public static void adjustRowHeightForRowWithNonMergedCells(Row row) {
row.setHeight((short) -1);
}
public static void adjustRowHeightForRowWithMergedCells(Row row) {
Sheet sheet = row.getSheet();
Cell longestTextCell = null;
//Potřebujeme získat buňku s nejdelším textem
for (Cell iteratedCell : row) {
String iteratedTextString = iteratedCell.getStringCellValue();
if (longestTextCell != null && StringUtils.isNotBlank(longestTextCell.getStringCellValue())) {
if (iteratedTextString.length() > longestTextCell.getStringCellValue().length()) {
longestTextCell = iteratedCell;
}
} else {
longestTextCell = iteratedCell;
}
}
//Z textově nejobsáhlejší buňky potřebujeme dostat údaje
String longestText = "";
if (StringUtils.isNotBlank(longestTextCell.getStringCellValue()) && longestTextCell != null) {
longestText = longestTextCell.getStringCellValue();
//Protože textově nejobsáhlejší buňka nemusí nutně být sloučeného typu, je zapotřebí to všude ošetřit
Boolean isLongestTextCellMerged = isCellMerged(longestTextCell);
Float longestCellWidthInPixels = 0f;
Float longestMergedCellWidthInPixels = 0f;
//Získat šířku nesloučené nejobsáhlejší buňky je jednoduché
if (!isLongestTextCellMerged) {
Integer longestCellColumnIndex = longestTextCell.getColumnIndex();
longestCellWidthInPixels = sheet.getColumnWidthInPixels(longestCellColumnIndex);
} else {
//Musíme přijít na šířku sloučené buňky namísto buňky uvnitř sloučené buňky
List<List<Cell>> cellsInMergedRegion = getCellsInRowsInsideRegionRange(longestTextCell);
longestMergedCellWidthInPixels = 0f;
//Projdeme řádky
for (List<Cell> iteratedCell2List : cellsInMergedRegion) {
Float iteratedMergedCell2WidthInPixels = 0f;
//Projdeme jednotlivé buňky ve sloučené buňce na řádku a sečteme jejich šířky
for (Cell iteratedCell2 : iteratedCell2List) {
Integer iteratedCell2ColumnIndex = iteratedCell2.getColumnIndex();
Float iteratedCell2ColumnWidthInPixels = sheet.getColumnWidthInPixels(iteratedCell2ColumnIndex);
iteratedMergedCell2WidthInPixels = iteratedMergedCell2WidthInPixels + iteratedCell2ColumnWidthInPixels;
}
//Získáme šířku nejširší sloučené buňky na řádku
if (iteratedMergedCell2WidthInPixels > longestMergedCellWidthInPixels) {
longestMergedCellWidthInPixels = iteratedMergedCell2WidthInPixels;
}
//Resetujeme sčítání
iteratedMergedCell2WidthInPixels = 0f;
}
}
//Uložíme si nejširší buňku dle toho, zda je sloučená či nikoliv
Float longestWidthInPixels;
if (isLongestTextCellMerged) {
longestWidthInPixels = longestMergedCellWidthInPixels;
} else {
longestWidthInPixels = longestCellWidthInPixels;
}
//Potřebujeme font
Workbook wb = sheet.getWorkbook();
Short fontIndex = longestTextCell.getCellStyle().getFontIndex();
Font excelFont = wb.getFontAt(fontIndex);
//Potřebujeme i jeho styl
Integer excelFontStyle = java.awt.Font.PLAIN;
if (excelFont.getBold()) excelFontStyle = java.awt.Font.BOLD;
if (excelFont.getItalic()) excelFontStyle = java.awt.Font.ITALIC;
//Potřebujeme získat skutečný font i s velikostí
java.awt.Font currentFont = new java.awt.Font(excelFont.getFontName(), excelFontStyle, excelFont.getFontHeightInPoints());
//Získáme řetězec s vlastností
AttributedString attributedString = new AttributedString(longestText);
attributedString.addAttribute(TextAttribute.FONT, currentFont);
//Použijeme LineBreakMeasurer k zjištění kolik řádků bude text potřebovat
FontRenderContext fontRenderContext = new FontRenderContext(null, true, true);
LineBreakMeasurer measurer = new LineBreakMeasurer(attributedString.getIterator(), fontRenderContext);
Integer nextPosition = 0;
Integer lineCount = 0;
while (measurer.getPosition() < longestText.length()) {
nextPosition = measurer.nextOffset(longestWidthInPixels);
//Také musíme ošetřit případ manuálně zadaných LineBreaků pro všechny možné techtle mechtle :-S
String textLine = StringUtils.substring(longestText, measurer.getPosition(), nextPosition);
Boolean containsNewLine = StringUtils.containsIgnoreCase(textLine, "\r") || StringUtils.containsIgnoreCase(textLine, "\\r") || StringUtils.containsIgnoreCase(textLine, "\n") || StringUtils.containsIgnoreCase(textLine, "\\n");
if (containsNewLine) {
if (StringUtils.containsIgnoreCase(textLine, "\r\n") || StringUtils.containsIgnoreCase(textLine, "\\r\\n")) {
lineCount = lineCount + StringUtils.countMatches(textLine, "\n");
} else {
if (StringUtils.containsIgnoreCase(textLine, "\r") || StringUtils.containsIgnoreCase(textLine, "\\r")) {
lineCount = lineCount + StringUtils.countMatches(textLine, "\r");
}
if (StringUtils.containsIgnoreCase(textLine, "\n") || StringUtils.containsIgnoreCase(textLine, "\\n")) {
lineCount = lineCount + StringUtils.countMatches(textLine, "\n");
}
}
lineCount = lineCount + StringUtils.countMatches(textLine, "\\r?\\n");
}
lineCount++;
measurer.setPosition(nextPosition);
}
//Máme počet řádků, zbývá konečný dopočet výšky řádku a jeho použití
if (lineCount > 1) {
Float fontHeight = currentFont.getLineMetrics(longestText, fontRenderContext).getHeight();
//Pro jistotu přidáme jeden řádek navíc, člověk nikdy neví...
lineCount = lineCount + 1;
//Potřebujeme získat poslední řádek
Row lastRow = null;
if (isCellMerged(longestTextCell)) {
List<List<Cell>> mergedCellsInRows = getCellsInRowsInsideRegionRange(longestTextCell);
Integer lastRowInMergedSectionIndex = mergedCellsInRows.size() - 1;
List<Cell> lastRowInMergedSection = mergedCellsInRows.get(lastRowInMergedSectionIndex);
lastRow = lastRowInMergedSection.get(0).getRow();
} else {
lastRow = longestTextCell.getRow();
}
//Je potřeba ošetřit velikosti, pokud má sloučená buňka vícero řádků
Float cellsMergedAboveHeight = 0f;
if (isCellMerged(longestTextCell)) {
if (getCellsInRowsInsideRegionRange(longestTextCell).size() > 1) {
List<List<Cell>> mergedCellsInRows = getCellsInRowsInsideRegionRange(longestTextCell);
for (List<Cell> rowsWithCells : mergedCellsInRows){
if (!lastRow.equals(rowsWithCells.get(0).getRow())){
cellsMergedAboveHeight = cellsMergedAboveHeight + rowsWithCells.get(0).getRow().getHeight();
}
}
}
}
//Vzorec je ((Velikost fontu krát počet řádků plus (počet řádků krát volný prostor mezi řádky)) krát přepočet Excelu) mínus výška sloučených buněk nad posledním řádkem.
Short finalRowHeight = (short) (((fontHeight * lineCount + (lineCount * 15))* 10) - cellsMergedAboveHeight);
//A výsledek nastavíme na poslední řádek, protože jinak to przní sloupce vlevo a vpravo od vyšších řádků
lastRow.setHeight(finalRowHeight);
}
}
}
I was having a similar problem where row height was not adjusting for merged cells.
I had to write a custom function for adjusting height of that particular row. Here is my code:
I have fixed column width in my sheet to be 24, and default font size to be 11.
I needed adjustment in row height whenever my font size > 11 and cell text length is overflowing the column width or isn't visible properly due to larger length.
private void adjustRowHeightMergedCells(final XSSFCell mergedCell) {
DataFormatter dataFormatter = new DataFormatter();
int defaultCharWidth = SheetUtil.getDefaultCharWidth(mergedCell.getRow().getSheet().getWorkbook());
XSSFRow row = mergedCell.getRow();
// Getting merged cell width value
double cellValueWidth = SheetUtil.getCellWidth(mergedCell, defaultCharWidth, dataFormatter, true);
// If cell width value > 24 (Default value), calculate how much extra row height is needed
// This happends when text length is larger than the column width (24)
float extraRowHeightDueToCellTextLength = (float) Math.floor(cellValueWidth / 24) * row.getHeightInPoints();
float extraRowHeightDueToCellTextFontSize = 0;
// If cell font size > 11 (Default value), calculate how much extra row height is needed
short cellTextFontSize = mergedCell.getCellStyle().getFont().getFontHeightInPoints();
if (cellTextFontSize > 11) {
extraRowHeightDueToCellTextFontSize = (cellTextFontSize-ExcelConstants.DEFAULT_FONT_SIZE) * (5f/3f);
}
// 5f/3f in above calculation is custom number which assumed by thinking that for font size 11, my row height shud be 15, and for example custom font size 20, row height shud be 30, hence the factor 5f/ 3f( per extra 1 point increase in font size above 11, row height shud be increased by 5/3)
// Larger of two adjustment values will be taken and added to current row height
float extraRowHeightAdjustment = Math.max(extraRowHeightDueToCellTextFontSize,extraRowHeightDueToCellTextLength);
if(extraRowHeightAdjustment > 0) {
row.setHeightInPoints(row.getHeightInPoints() + extraRowHeightAdjustment);
}
}
Kinda hacky solution but works for my situation, you can modify it per your requirements.
After more research, turns out that this is a problem with Excel itself, not POI. Excel does indeed lose its ability to auto-fit rows to content for all rows that have merged cells in them. For more info see:
http://excel.tips.net/T003207_Automatic_Row_Height_For_Merged_Cells_with_Text_Wrap.html
http://blog.contextures.com/archives/2012/06/07/autofit-merged-cell-row-height/
The workaround is based on predicting the number of lines in the largest cell of the row, and then adjusting the row height manually. The code is based on this discussion:
http://mail-archives.apache.org/mod_mbox/poi-user/200906.mbox/%3C24216153.post#talk.nabble.com%3E
RowInfo and NestedCellInfo below are my custom data structures that keep track of the sheet layout. You should be able to replace these with your equivalents and helper functions.
private void adjustRowHeights(Sheet sheet, List<RowInfo> rows, SortedSet<Integer> createdColumnNumbers) {
SortedMap<Integer, Float> columnWidthsInPx = [] as TreeMap;
createdColumnNumbers.each {
columnWidthsInPx.put(it, sheet.getColumnWidthInPixels(it));
}
rows.each { RowInfo rowInfo ->
if ( rowInfo.hasMergedCells ) {
Row excelRow = sheet.getRow(rowInfo.rowIndex);
// Find the column with the longest text - that's the one that will determine
// the row height
//
NestedCellInfo longestCell = rowInfo.getCellWithLongestContent();
String cellText = longestCell.getText();
if ( cellText != null && cellText.size() > 5 ) {
int colIdx = rowInfo.cells.indexOf(longestCell);
// Figure out available width in pixels, taking colspans into account
//
float columnWidthInPx = columnWidthsInPx[colIdx];
int numberOfMergedColumns = longestCell.colSpan;
(numberOfMergedColumns - 1).times {
columnWidthInPx += columnWidthsInPx[colIdx + it];
}
// Setup the font we'll use for figuring out where the text will be wrapped
//
XSSFFont cellFont = longestCell.getCellFont();
int fontStyle = Font.PLAIN;
if ( cellFont.getBold() ) fontStyle = Font.BOLD;
if ( cellFont.getItalic() ) fontStyle = Font.ITALIC;
java.awt.Font currFont = new java.awt.Font(
cellFont.getFontName(),
fontStyle,
cellFont.getFontHeightInPoints());
AttributedString attrStr = new AttributedString(cellText);
attrStr.addAttribute(TextAttribute.FONT, currFont);
// Use LineBreakMeasurer to count number of lines needed for the text
//
FontRenderContext frc = new FontRenderContext(null, true, true);
LineBreakMeasurer measurer = new LineBreakMeasurer(attrStr.getIterator(), frc);
int nextPos = 0;
int lineCnt = 0;
while (measurer.getPosition() < cellText.length()) {
nextPos = measurer.nextOffset( columnWidthInPx );
lineCnt++;
measurer.setPosition(nextPos);
}
if ( lineCnt > 1 ) {
excelRow.setHeight((short)(excelRow.getHeight() * lineCnt * /* fudge factor */ 0.7));
}
}
}
}
This solution is far from perfect, but it allowed me to move forward.
I'm loading in Assets from the main game class which extends the libgdx class game. In the create() method of that class i'm calling Assets.loadAtlas(); and this calls:
public static void loadAtlas() {
String textureFile = "data/rubenSprite.txt";
myTextures = new TextureAtlas(Gdx.files.internal(textureFile));
TextureRegion[] walkRightFrames = new TextureRegion[4];
for (int i = 0; i < 5; i++)
{
walkRightFrames[i] = myTextures.findRegion("wframe" + (i + 1));
}
rubenWalkRight = new Animation(0.2f, walkRightFrames[0], walkRightFrames[1],
walkRightFrames[2], walkRightFrames[3], walkRightFrames[4]);
TextureRegion[] walkLeftFrames = new TextureRegion[4];
for (int i = 0; i < 5; i++)
{
walkLeftFrames[i] = new TextureRegion(walkRightFrames[i]);
walkLeftFrames[i].flip(true,false);
}
rubenWalkLeft = new Animation(0.2f, walkLeftFrames[0], walkLeftFrames[1],
walkLeftFrames[2], walkLeftFrames[3], walkLeftFrames[4]);
TextureRegion[] idleRightFrames = new TextureRegion[3];
for (int i = 0; i < 4; i ++)
{
idleRightFrames[i] = myTextures.findRegion("iframe" + (i + 1));
}
rubenIdleRight = new Animation(0.2f, idleRightFrames[0], idleRightFrames[1],
idleRightFrames[2], idleRightFrames[3]);
TextureRegion[] idleLeftFrames = new TextureRegion[3];
for (int i = 0; i < 4; i++)
{
idleLeftFrames[i] = new TextureRegion(idleRightFrames[i]);
idleLeftFrames[i].flip(true,false);
}
rubenIdleLeft = new Animation(0.2f, idleLeftFrames[0], idleLeftFrames[1],
idleLeftFrames[2], idleLeftFrames[3]);
TextureRegion[] jumpRightFrames = new TextureRegion[4];
for (int i = 0; i < 5; i++)
{
jumpRightFrames[i] = myTextures.findRegion("jframe" + (i + 1));
}
rubenJumpRight = new Animation(0.2f, jumpRightFrames[0], jumpRightFrames[1],
jumpRightFrames[2], jumpRightFrames[3], jumpRightFrames[4]);
TextureRegion[] jumpLeftFrames = new TextureRegion[4];
for (int i = 0; i < 5; i++)
{
jumpLeftFrames[i] = new TextureRegion(jumpRightFrames[i]);
jumpLeftFrames[i].flip(true,false);
}
rubenJumpLeft = new Animation(0.2f, jumpLeftFrames[0], jumpLeftFrames[1],
jumpLeftFrames[2], jumpLeftFrames[3], jumpLeftFrames[4]);
TextureRegion fallRight = new TextureRegion();
fallRight = myTextures.findRegion("fall");
rubenFallRight = new Animation(0f, fallRight);
TextureRegion fallLeft = new TextureRegion(fallRight); ;
fallLeft.flip(true,false);
rubenFallLeft = new Animation(0f, fallLeft);
}
From the tutorials I've looked at, it seems correct to me. I've given the player states and drawn the animations within them inside the mainRenderer depending on the state the player is in. This code seems fine also:
private void renderRuben () {
TextureRegion keyFrame;
switch (world.ruben.getState()) {
case Ruben.RUBEN_STATE_HIT:
keyFrame = Assets.bobHit;
break;
case Ruben.RUBEN_STATE_WALKING:
if (Ruben.facingRight == true)
{
keyFrame = Assets.rubenWalkRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
else
{
keyFrame = Assets.rubenWalkLeft.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
case Ruben.RUBEN_STATE_FALL:
if (Ruben.facingRight == true) {
keyFrame = Assets.rubenFallRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
else {
keyFrame = Assets.rubenFallLeft.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
case Ruben.RUBEN_STATE_JUMP:
if (Ruben.facingRight == true) {
keyFrame = Assets.rubenJumpRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
else {
keyFrame = Assets.rubenJumpRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_NONLOOPING);
break;
}
case Ruben.RUBEN_STATE_IDLE:
default:
if (Ruben.facingRight == true) {
keyFrame = Assets.rubenIdleRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_LOOPING);
}
else {
keyFrame = Assets.rubenIdleRight.getKeyFrame(world.ruben.getStateTime(), Animation.ANIMATION_LOOPING);
}
}
float side = world.ruben.getVelocity().x < 0 ? -1 : 1;
if (side < 0)
batch.draw(keyFrame, world.ruben.position.x + 0.5f, world.ruben.position.y - 0.5f, side * Ruben.RUBEN_WIDTH, Ruben.RUBEN_HEIGHT);
else
batch.draw(keyFrame, world.ruben.position.x - 0.5f, world.ruben.position.y - 0.5f, side * Ruben.RUBEN_WIDTH, Ruben.RUBEN_HEIGHT);
}
I packed the Atlases using TexturePacker GUI and saved the png and txt file into /assets/data folder.
The overall project has no errors, it just says 'application not responding' when it opens up in the emulator. What am i doing wrong?
Create Method for game class:
public class GameView extends Game {
// used by all screens
public SpriteBatch batcher;
#Override
public void create () {
batcher = new SpriteBatch();
Settings.load();
Assets.loadAtlas();
setScreen(new MainMenuScreen(this));
}
}
Overall it was something to do with the Emulator not the application, The emulator wasn't compatible with Open GL ES 2.0, So I downloaded GenyMotion and now it works fine.
http://www.genymobile.com/en/
i've created a BarChart using jfreechart in java. The bar is plotted according to the days in a month. for example this month March contains 31 days, so there will be 31 bars . The problem is that when i click the next button the month changes to April which contains 30 days, ie 30 bars. How can we change the BarChart according to the days in a month on button click.
Can anyone please tell me how to do that.
You need to update your dataset with each change. I've added an updateDataset() method and called it in several key places.
private void updateDataset() {
dataset.clear();
for (int i = 1; i <= finalday; i++) {
dataset.setValue(i, "Marks", "" + i);
}
Notes:
Do not use absolute layout; let the layout do its work.
Do not do date arithmetic yourself; use Calendar, for example.
Do not call overridable methods in the constructor.
Do re-factor your code to limit the number and scope of variables.
Do use meaningful names, especially for instance variables.
SSCCE, incompletely revised:
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
public class BarGraph {
public int count = 0, count1 = 0, count2 = 0, count3 = 0, count4 = 0;
public int contstatus = 2;
public int date, year, mon, fn, show = 0, finalday, leapcn = 0, task = 0;
String startdte, enddte, monthweek, leavedates = "", nneed = "", year4enab, month4enab, days;
ChartFrame frame;
public static int st = 0;
JButton left = new JButton("<");
JButton right = new JButton(">");
JComboBox month = new JComboBox();
JSpinner yearspin = new javax.swing.JSpinner();
JLabel monthLabel = new javax.swing.JLabel();
JLabel yearLabel = new javax.swing.JLabel();
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
BarGraph() {
task = 1;
Calendar cal;
left.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
left.setRequestFocusEnabled(false);
left.addActionListener(new java.awt.event.ActionListener() {
#Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
leftActionPerformed(evt);
}
});
right.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
right.setRequestFocusEnabled(false);
right.addActionListener(new java.awt.event.ActionListener() {
#Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
rightActionPerformed(evt);
}
});
month.setMaximumRowCount(12);
month.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}));
month.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
month.addItemListener(new java.awt.event.ItemListener() {
#Override
public void itemStateChanged(java.awt.event.ItemEvent evt) {
monthItemStateChanged(evt);
}
});
yearspin.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
yearspin.setValue(year);
yearspin.addChangeListener(new javax.swing.event.ChangeListener() {
#Override
public void stateChanged(javax.swing.event.ChangeEvent evt) {
yearspinStateChanged(evt);
}
});
monthLabel.setBackground(new java.awt.Color(255, 255, 255));
monthLabel.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
monthLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
monthLabel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, java.awt.Color.black, null, null));
monthLabel.setOpaque(true);
monthLabel.setText("SEPTEMBER");
yearLabel.setBackground(new java.awt.Color(255, 255, 255));
yearLabel.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
yearLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
yearLabel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, java.awt.Color.black, null, null));
yearLabel.setOpaque(true);
yearLabel.setText("2013");
cal = new GregorianCalendar();
year = cal.get(Calendar.YEAR);
mon = cal.get(Calendar.MONTH);
date = cal.get(Calendar.DATE);
yearspin.setValue(year);
month.setSelectedIndex(mon);
calendar(year, mon);
month4enab = getMonth(monthLabel.getText());
year4enab = yearLabel.getText();
startdte = year4enab + "-" + month4enab + "-01";
enddte = year4enab + "-" + month4enab + "-" + finalday;
}
public static void main(String[] args) {
new BarGraph().showBar();
}
private void leftActionPerformed(ActionEvent evt) {
show = 0;
if (mon == 0) {
year--;
mon = 11;
} else {
mon--;
}
yearspin.setValue(year);
month.setSelectedIndex(mon);
display();
calendar(year, mon);
displayCalendar();
updateDataset();
}
private void rightActionPerformed(ActionEvent evt) {
show = 0;
if (mon == 11) {
year++;
mon = 0;
} else {
mon++;
}
yearspin.setValue(year);
month.setSelectedIndex(mon);
display();
calendar(year, mon);
displayCalendar();
updateDataset();
}
private void displayCalendar() {
month4enab = getMonth(monthLabel.getText());
year4enab = yearLabel.getText();
startdte = year4enab + "-" + month4enab + "-01";
enddte = year4enab + "-" + month4enab + "-" + finalday;
}
private void monthItemStateChanged(ItemEvent evt) {
show = 0;
String s = (String) month.getSelectedItem();
if ("January".equals(s)) {
mon = 0;
}
if ("February".equals(s)) {
mon = 1;
}
if ("March".equals(s)) {
mon = 2;
}
if ("April".equals(s)) {
mon = 3;
}
if ("May".equals(s)) {
mon = 4;
}
if ("June".equals(s)) {
mon = 5;
}
if ("July".equals(s)) {
mon = 6;
}
if ("August".equals(s)) {
mon = 7;
}
if ("September".equals(s)) {
mon = 8;
}
if ("October".equals(s)) {
mon = 9;
}
if ("November".equals(s)) {
mon = 10;
}
if ("December".equals(s)) {
mon = 11;
}
display();
calendar(year, mon);
updateDataset();
}
private void yearspinStateChanged(ChangeEvent evt) {
show = 0;
year = (Integer) yearspin.getValue();
display();
calendar(year, mon);
updateDataset();
}
public void display() {
String month = "", day = "";
if (mon < 9) {
month = "0" + (mon + 1);
} else {
month = "" + (mon + 1);
}
if (nneed.length() < 2) {
day = "0" + nneed;
} else {
day = "" + nneed;
}
String datss = year + "-" + (month) + "-" + day;
switch (mon) {
case 0:
monthLabel.setText("JANUARY");
break;
case 1:
monthLabel.setText("FEBRUARY");
break;
case 2:
monthLabel.setText("MARCH");
break;
case 3:
monthLabel.setText("APRIL");
break;
case 4:
monthLabel.setText("MAY");
break;
case 5:
monthLabel.setText("JUNE");
break;
case 6:
monthLabel.setText("JULY");
break;
case 7:
monthLabel.setText("AUGUST");
break;
case 8:
monthLabel.setText("SEPTEMBER");
break;
case 9:
monthLabel.setText("OCTOBER");
break;
case 10:
monthLabel.setText("NOVEMBER");
break;
case 11:
monthLabel.setText("DECEMBER");
break;
}
yearLabel.setText(String.valueOf(year));
}
public void calendar(int year, int mon) {
int year1 = year;
int count1 = 1, fun = 0, day, day1 = 0, key = 0, k = -1, s = 1, ck = 2, cheak, y = 0;
day1 = year % 100;
fun = 1 + (day1 / 4);
switch (mon) {
case 0:
key = 1;
k = -1;
break;
case 1:
key = 4;
k = 0;
break;
case 2:
key = 4;
k = 0;
break;
case 3:
key = 0;
k = 0;
break;
case 4:
key = 2;
k = 0;
break;
case 5:
key = 5;
k = 0;
break;
case 6:
key = 0;
k = 0;
break;
case 7:
key = 3;
k = 0;
break;
case 8:
key = 6;
k = 0;
break;
case 9:
key = 1;
k = 0;
break;
case 10:
key = 4;
k = 0;
break;
case 11:
key = 6;
k = 0;
break;
}
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
k = -1;
day = 29;
leapcn = 0;
if (mon == 0 || mon == 1) {
leapcn = 1;
}
} else {
k = 0;
day = 28;
leapcn = 1;
}
if (year >= 2000) {
y = 6;
}
if (year <= 1900 && year > 2000) {
y = 0;
}
fun = fun + key + k + y;
fun = (fun + day1) % 7;
if (fun == 0) {
fun = 7;
}
if (mon == 0 || mon == 2 || mon == 4 || mon == 6 || mon == 7 || mon == 9 || mon == 11) {
day = 31;
}
if (mon == 3 || mon == 5 || mon == 8 || mon == 10) {
day = 30;
}
finalday = day;
System.out.println("DAYS IN THIS MONTHS:" + finalday);
cheak = fun + 1;
s++;
}
public static String getMonth(String s) {
String mont = "56";
if ("January".equalsIgnoreCase(s)) {
mont = "01";
} else if ("February".equalsIgnoreCase(s)) {
mont = "02";
} else if ("March".equalsIgnoreCase(s)) {
mont = "03";
} else if ("April".equalsIgnoreCase(s)) {
mont = "04";
} else if ("May".equalsIgnoreCase(s)) {
mont = "05";
} else if ("June".equalsIgnoreCase(s)) {
mont = "06";
} else if ("July".equalsIgnoreCase(s)) {
mont = "07";
} else if ("August".equalsIgnoreCase(s)) {
mont = "08";
} else if ("September".equalsIgnoreCase(s)) {
mont = "09";
} else if ("October".equalsIgnoreCase(s)) {
mont = "10";
} else if ("November".equalsIgnoreCase(s)) {
mont = "11";
} else if ("December".equalsIgnoreCase(s)) {
mont = "12";
}
return mont;
}
private void showBar() {
for (int i = 1; i <= finalday; i++) {
dataset.setValue(i, "Marks", "" + i);
}
JFreeChart chart = ChartFactory.createBarChart(" ", "Student", "Marks",
dataset, PlotOrientation.VERTICAL, false, true, false);
chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(new Color(221, 223, 238));
plot.setRangeGridlinePaint(Color.white);
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setSeriesPaint(0, new Color(231, 175, 61));
renderer.setSeriesPaint(1, Color.green);
renderer.setDrawBarOutline(false);
renderer.setShadowVisible(false);
chart.setBackgroundPaint(Color.WHITE);
chart.getTitle().setPaint(Color.blue);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.BLUE);
frame = new ChartFrame("Bar Chart", chart);
frame.add(month);
frame.add(left);
frame.add(right);
frame.add(yearspin);
frame.add(monthLabel);
frame.add(yearLabel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void updateDataset() {
dataset.clear();
for (int i = 1; i <= finalday; i++) {
dataset.setValue(i, "Marks", "" + i);
}
}
}