Jump to content
Software FX Community

Bar chart with temporal series


delphine

Recommended Posts

Hi,

I'm using ChartFx 7, and I tried to create a bar chart with temporal series.

I tried to convert the date with Chart.datetoNumber(Date) but there is an issue=> Bars and points are shifted, the last bar is out of the chart.If serie is not temporal (no dates in x axis), work like a charm.

example code

Chart chart1 = new Chart();// serie 1chart1.getData().getX().set(0, 0, Chart.dateToNumber(new GregorianCalendar(2000, 1, 1)));chart1.getData().getY().set(0, 0, 18.0);chart1.getData().getX().set(0, 1, Chart.dateToNumber(new GregorianCalendar(2000, 1, 2)));chart1.getData().getY().set(0, 1, 2.0);chart1.getData().getX().set(0, 2, Chart.dateToNumber(new GregorianCalendar(2000, 1, 3)));chart1.getData().getY().set(0, 2, 15.0);chart1.getData().getX().set(0, 3, Chart.dateToNumber(new GregorianCalendar(2000, 1, 4)));chart1.getData().getY().set(0, 3, 6.0);chart1.getData().getX().set(0, 4, Chart.dateToNumber(new GregorianCalendar(2000, 1, 5)));chart1.getData().getY().set(0, 4, 10.0);chart1.getData().getX().set(0, 5, Chart.dateToNumber(new GregorianCalendar(2000, 1, 6)));chart1.getData().getY().set(0, 5, 4.0);

// serie 2chart1.getData().getX().set(1, 0, Chart.dateToNumber(new GregorianCalendar(2000, 1, 1)));chart1.getData().getY().set(1, 0, 36.0);chart1.getData().getX().set(1, 1, Chart.dateToNumber(new GregorianCalendar(2000, 1, 2)));chart1.getData().getY().set(1, 1, 4.0);chart1.getData().getX().set(1, 2, Chart.dateToNumber(new GregorianCalendar(2000, 1, 3)));chart1.getData().getY().set(1, 2, 30.0);chart1.getData().getX().set(1, 3, Chart.dateToNumber(new GregorianCalendar(2000, 1, 4)));chart1.getData().getY().set(1, 3, 12.0);chart1.getData().getX().set(1, 4, Chart.dateToNumber(new GregorianCalendar(2000, 1, 5)));chart1.getData().getY().set(1, 4, 20.0);chart1.getData().getX().set(1, 5, Chart.dateToNumber(new GregorianCalendar(2000, 1, 6)));chart1.getData().getY().set(1, 5, 8.0);chart1.getSeries().get(0).setGallery(Gallery.SCATTER);chart1.getSeries().get(1).setGallery(Gallery.BAR);chart1.getAxisX().getLabelsFormat().setFormat(AxisFormat.DATE);chart1.getLegendBox().setVisible(false);chart1.setWidth(600);chart1.setHeight(400);

 

On this example, series have the same date but points and bars are not aligned. 

Someone can help me in order to have points and bars aligned?

Yours faithfully,

Delphine 

Link to comment
Share on other sites

Hi,

with your code, it works correctly, but I have another problem now.

Series that I'm using have not necessarily the same date, and I can't represent them well on chart.

On first chart, I have two series with different dates for each point but points and bars are aligned.

On second chart, I changed the index but now I have "holes" in representation of first serie and I don't want to have "holes" on my chart.

If I don't use this chart1.getAllSeries().setGallery(Gallery.BAR); at the beginning of my code, I have a slight lag.

Code for first example :

Chart chart1 = new Chart();

chart1.getAllSeries().setGallery(Gallery.BAR);

// serie 1

chart1.getData().getX().set(0, 0, Chart.dateToNumber(new GregorianCalendar(2000, 1, 1)));

chart1.getData().getY().set(0, 0, 18.0);

chart1.getData().getX().set(0, 1, Chart.dateToNumber(new GregorianCalendar(2000, 1, 2)));

chart1.getData().getY().set(0, 1, 2.0);

chart1.getData().getX().set(0, 2, Chart.dateToNumber(new GregorianCalendar(2000, 1, 3)));

chart1.getData().getY().set(0, 2, 15.0);

chart1.getData().getX().set(0, 3, Chart.dateToNumber(new GregorianCalendar(2000, 1, 4)));

chart1.getData().getY().set(0, 3, 6.0);

chart1.getData().getX().set(0, 4, Chart.dateToNumber(new GregorianCalendar(2000, 1, 5)));

chart1.getData().getY().set(0, 4, 10.0);

chart1.getData().getX().set(0, 5, Chart.dateToNumber(new GregorianCalendar(2000, 2, 20)));

chart1.getData().getY().set(0, 5, 4.0);

// serie 2

chart1.getData().getX().set(1, 0, Chart.dateToNumber(new GregorianCalendar(2000, 2, 1)));

chart1.getData().getY().set(1, 0, 36.0);

chart1.getData().getX().set(1, 1, Chart.dateToNumber(new GregorianCalendar(2000, 2, 2)));

chart1.getData().getY().set(1, 1, 4.0);

chart1.getData().getX().set(1, 2, Chart.dateToNumber(new GregorianCalendar(2000, 2, 3)));

chart1.getData().getY().set(1, 2, 30.0);

chart1.getData().getX().set(1, 3, Chart.dateToNumber(new GregorianCalendar(2000, 2, 4)));

chart1.getData().getY().set(1, 3, 12.0);

chart1.getData().getX().set(1, 4, Chart.dateToNumber(new GregorianCalendar(2000, 2, 5)));

chart1.getData().getY().set(1, 4, 20.0);

chart1.getData().getX().set(1, 5, Chart.dateToNumber(new GregorianCalendar(2000, 2, 6)));

chart1.getData().getY().set(1, 5, 8.0);

chart1.getSeries().get(0).setGallery(Gallery.LINES);

chart1.getSeries().get(1).setGallery(Gallery.BAR);

chart1.getAxisX().setForceZero(false);

chart1.getAxisX().getLabelsFormat().setFormat(AxisFormat.DATE);

Can you tell me how I can display data on chart in order to have same chart like last one on picture but with bars instead of points ?

Yours faithfully,

Delphine

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...