Jump to content
Software FX Community

Gap between the Y axis and chart


DeepthiRH

Recommended Posts

Hello,

All the charts in chartfx seem to have a small gap between the Y axis and the actual chart.

Am working on an area chart.

How can i take out the gap between the Y axis and the area chart so that the chart Sticks to Y axis.

Below is my code:

The set height and width also doesnot seem to work. Please help me out

 

ChartServer chart1 = new ChartServer(application, request, response);

 

List<MarketDTO> chartList = (List<MarketDTO>) request

.getAttribute("chart");chart1.getAxisY().setAutoScale(false);

Axis yaxis = chart1.getAxisY();

 

//chart1.getAxisX().setStyle(AxisStyle.FORCE_ZERO);FlashWriter w = new FlashWriter();

 

chart1.setGallery(Gallery.AREA);

 

chart1.setGrid(ChartGrid.HORZ | ChartGrid.VERT);

 

chart1.getSeries(0).setColor(java.awt.Color.red);

chart1.openData(COD.VALUES, 1, chartList.size());

//Find the max value to plot the Y axis and also get the chart points to plot the area graphlong maxValue = 0;long minValue = 0;

 

 

for (int i = 0; i < chartList.size(); i++) {

MarketDTO chartDTO = chartList.get(i);

 

 

if (request.getParameter("Nifty") != null) {

 

chart1.getAxisX().getTitle().setText("Time");

chart1.getAxisY().getTitle().setText(

"NSC Price List");chart1.setInsideColor(new java.awt.Color(66, 66, 66));

chart1.setBackColor(java.awt.Color.white);

chart1.setBorder(false);chart1.setImgSizeable(true);

chart1.setImgHeight(100);

chart1.setImgWidth(100);

chart1.setHeight(100);

chart1.setWidth(100);

chart1.setLeftGap(0);

chart1.setRightGap(0);

chart1.setBottomGap(0);

chart1.setTopGap(0);

Long chartValue = chartDTO.getClosePrice();

if (chartValue > maxValue)

maxValue = chartValue;

if (i == 0)

minValue = chartValue;

if (chartValue < minValue)

minValue = chartValue;

chart1.setValue(1, i, chartValue);

} else {

chart1.getAxisX().getTitle().setText(

"Time");chart1.getAxisY().getTitle().setText("BSC Price List");chart1.setInsideColor(new java.awt.Color(192, 192, 192));

chart1.setBackColor(java.awt.Color.magenta);

chart1.setBorder(false);

 

Long chartValue = chartDTO.getPrice();

 

if (chartValue > maxValue)

maxValue = chartValue;

if (i == 0)

minValue = chartValue;

if (chartValue < minValue)

minValue = chartValue;

chart1.setValue(1, i, chartValue);

}

}

 

// to round maxValue off to nearest max hundred int temp = 0;

temp = (

int) Math.round(maxValue);int mod = 0;

mod = temp % 100;

int maxresult = 0;if (mod == 0) {

maxresult = temp;

} else if (mod != 0) {

maxresult = temp - mod + 100;

}

//to round off minValue nearest min hundredint temp1 = 0;

temp1 = (

int) Math.round(minValue);int mod1 = 0;

mod1 = temp1 % 100;

int minresult = 0;if (mod1 == 0) {

minresult = temp1;

} else if (mod1 != 0) {

minresult = temp1 - mod1;

}

int setRange = 0;

setRange = (maxresult - minresult) / 4;

 

out.flush();

out.write(minresult);

 

yaxis.setMin(minresult);

yaxis.setMax(maxresult);

yaxis.setStep(setRange);

chart1.closeData(COD.VALUES);

 

// Assign all labels (this will help in tooltips)

java.util.Date dateTime = new java.util.Date();java.util.GregorianCalendar cal = new java.util.GregorianCalendar();

 

for(int j=0;j<chartList.size();j++)

{

int hr=cal.get(cal.HOUR);if(hr>=10 || hr<11){

chart1.getLegend().setItem(j, java.text.DateFormat.getTimeInstance(3).format(dateTime));

cal.setTime(dateTime);

cal.add(java.util.Calendar.MINUTE,8);

dateTime = cal.getTime();

 

// Set the X axis

chart1.getAxisX().setFirstLabel((short) 1);

//chart1.getAxisX().setMin(10);chart1.getAxisX().setStep((short) 2);

//chart1.getAxisX().setMinorStep((short) 4);chart1.getAxisX().setFont(new java.awt.Font("Verdana",java.awt.Font.ROMAN_BASELINE,9));

}

else if(hr>=11 || hr<1){

 

chart1.getLegend().setItem(j, java.text.DateFormat.getTimeInstance(3).format(dateTime));

cal.setTime(dateTime);

cal.add(java.util.Calendar.MINUTE,20);

dateTime = cal.getTime();

 

// Set the X axis

chart1.getAxisX().setFirstLabel((short) 1);

//chart1.getAxisX().setMin(10);chart1.getAxisX().setStep((short) 5);

//chart1.getAxisX().setMinorStep((short) 4);chart1.getAxisX().setFont(new java.awt.Font("Verdana",java.awt.Font.ROMAN_BASELINE,9));

}

else{

 

chart1.getLegend().setItem(j, java.text.DateFormat.getTimeInstance(3).format(dateTime));

cal.setTime(dateTime);

cal.add(java.util.Calendar.MINUTE,20);

dateTime = cal.getTime();

 

// Set the X axis

chart1.getAxisX().setFirstLabel((short) 1);

//chart1.getAxisX().setMin(10);chart1.getAxisX().setStep((short) 20);

//chart1.getAxisX().setMinorStep((short) 4);chart1.getAxisX().setFont(new java.awt.Font("Verdana",java.awt.Font.ROMAN_BASELINE,9));

 

}

}

 

 

chart1.setOutputWriter(w);

%>

<%=

chart1.getHtmlTag("450", "280","FLASH")%>

Thanks,

Deepthi

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...