3D line chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
JfreeFan
Posts: 13
Joined: Fri Mar 23, 2007 12:11 pm

3D line chart

Post by JfreeFan » Wed Apr 04, 2007 11:46 am

Hi All,
Can any one suggest how to draw line chart with 3D effect.
I need to plot y point corresponding to its x points.
Thanks in advance

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Wed Apr 04, 2007 5:39 pm

Unfortunately, there is no ChartFactory.createXYLineChart3D() method, so you will have to construct the chart from the ground up. If you are willing to loose the 3D effect, you could just use ChartFactory.createXYLineChart(). I will note where in the steps below you can do this.

1. Add your data to a dataset. Use any of the XYDataset implementing classes. I would recommend the DefaultXYDataset for the application you briefly describe.

2. If you want to loose the 3d effect and just make a line chart, you can use ChartFactory.createXYLineChart() to create a JFreeChart using the dataset created in step 1. Skip to step 7. Otherwise, continue to step 3.

3. Instantiate a XYLine3DRenderer.

4. Instantiate two NumberAxis ; one for the domain and one for the range.

5. Create a XYPlot using the dataset created in step 1, the renderer in step 3, and the axes in step 4.

6. Create a JFreeChart from the plot created in step 5.

7. Take you JFreeChart created in either step 2 or 6 and add it to a ChartPanel if you are working in Swing. You can now use the chart panel as you would any Swing component. This final step varies if you are using SWT, but I do not know now the details there.

I hope this helps.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

JfreeFan
Posts: 13
Joined: Fri Mar 23, 2007 12:11 pm

3D line chart

Post by JfreeFan » Thu Apr 05, 2007 10:49 am

Richard,
Thanks for reply.I tried with steps you suggested.But unfortunatily its drawing 2D only.
I found CategoryPlot class can plot 3d Chart...
So genuine question how we can use CategoryPlot & CategoryDataset for drawing y-point with respect to x-point...
Any further suggestions are welcome.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: 3D line chart

Post by RichardWest » Thu Apr 05, 2007 5:07 pm

JfreeFan wrote:I tried with steps you suggested.But unfortunatily its drawing 2D only.
Did you try setting/adjusting the parameters that control the shadow in the XYLine3DRenderer? See setXOffest(double) and setYOffest(double) right below it.
JfreeFan wrote:I found CategoryPlot class can plot 3d Chart...
So genuine question how we can use CategoryPlot & CategoryDataset for drawing y-point with respect to x-point...
There is a 3d line renderer for the CategoryPlot, and you could assemble a DefaultCategoryDataset with your values. However, for you application, this is the wrong approach. This is especially true if you want to add a linear trend line as you comment in your other thread (please don't spam the forum with multiple related threads). The Regression class will help you generate coefficients for your trend line from your DefaultXYDataset. With this, you can create a LineFunction2D which you can query at several points and add the values to you DefaultXYDataset.
JFreeFan (from linked thread) wrote:By using default Category dataset i am able to draw 3d Line chart.But i also have to draw trend line chart on same chart.
But both domain & range axis get disturb.
:roll:
Can any one suggest how it can be achieved???
The problem you are having here is that you probably have different categories and/or number of categories in your data series and your trendline series. This problem will not occur if you use a DefaultXYDataset. A similar problem will occur if you use a DefaultTableXYDataset.

One general comment; why are you using 3d? The effect adds nothing to the plot apart from making it look fancy (i.e. good for marketing). If you are adding a trend line to the data, you are probably using this for something more scientific. Science prides itself on clean, presentable data with no fluffy/fancy effects. Stick with 2d, and the results will look much better. Just my opinion though.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

JfreeFan
Posts: 13
Joined: Fri Mar 23, 2007 12:11 pm

3D line Chart

Post by JfreeFan » Thu Apr 12, 2007 11:01 am

Hi,
Now i am able to draw 3d Line Chart by using DefaultCategoryDataset and CategoryAxis3D.But problem is as:
How i can manipulate column/row keys ??
Also as Richard suggest for trend line my line chart & trend line is drawing as 3D,but trend lines shrinks one position from start & end point.
Any Hint how to achieve???

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: 3D line Chart

Post by RichardWest » Fri Apr 13, 2007 12:10 am

JfreeFan wrote:Any Hint how to achieve???
I am afraid I have no clue what you are asking. What exactly do you want to manipulate with respect to the row and column keys? What do you mean by the trendline shrinking?
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

JfreeFan
Posts: 13
Joined: Fri Mar 23, 2007 12:11 pm

3D Line Chart

Post by JfreeFan » Fri Apr 13, 2007 12:06 pm

Hi,
Sorry i may not communicate properly.Here is image.
http://img99.imageshack.us/my.php?image=chartbv1.jpg
Its self explanatory and you will notice Trend line is drawing between 2-march To 6-March,where as its expected to be between 1-March to 7-March.
Thanks

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: 3D Line Chart

Post by RichardWest » Fri Apr 13, 2007 5:37 pm

JfreeFan wrote:Sorry i may not communicate properly.Here is image.
http://img99.imageshack.us/my.php?image=chartbv1.jpg
Its self explanatory and you will notice Trend line is drawing between 2-march To 6-March,where as its expected to be between 1-March to 7-March.
A picture is worth a thousand words in any language--I understand what you mean now. When you are creating the the trend line(s), what x-values do you use for the end points? I suspect you are just off by one in your loop somewhere. For instance, it is hard to get a trend line when there is only one point since you need two. Perhaps you are using the second point (2-March) instead of the first (1-March). As for the other end, perhaps you are not updating the trend line(s) correctly when your dataset updates.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

JfreeFan
Posts: 13
Joined: Fri Mar 23, 2007 12:11 pm

3D Line Chart

Post by JfreeFan » Sat Apr 14, 2007 5:58 am

Richard,
OK,I started in debugg mode & found value in loop is taking 01-March to 07-March.Also if i draw trend line in isolation i.e.without line chart it draws from 01-Mar to 07-Mar that is perfect.But combined with line chart it shrinks one position from both ends thats problem.
Appreciate your efforts to help me.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: 3D Line Chart

Post by RichardWest » Sat Apr 14, 2007 6:13 am

JfreeFan wrote:OK,I started in debugg mode & found value in loop is taking 01-March to 07-March. Also if i draw trend line in isolation i.e.without line chart it draws from 01-Mar to 07-Mar that is perfect.But combined with line chart it shrinks one position from both ends thats problem.
I am not sure. I am rapidly running out of common/obvious problems. One suggestion would be to switch to 2d to see what effect, if any, that has. It may also make things easier to debug since you are not going to be distracted by the visuals. Keep cutting variables out of the puzzle, and you will soon discover the problem.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

JfreeFan
Posts: 13
Joined: Fri Mar 23, 2007 12:11 pm

3D Line Chart

Post by JfreeFan » Wed Apr 18, 2007 11:42 am

Richard,
Some how i managed to solve trend line shrink problem.Now pls refer
http://img218.imageshack.us/my.php?imag ... nuezj7.png
chart & trend line gets discontinue where data value is null.I expect to draw in continuity.
How to draw chart in continuity??
any suggestion!!

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: 3D Line Chart

Post by RichardWest » Wed Apr 18, 2007 5:32 pm

JfreeFan wrote:chart & trend line gets discontinue where data value is null[/color].I expect to draw in continuity.
How to draw chart in continuity??
This is the expected behavior of the renderer. The only means to address this is override the renderer's draw() and change its behavior when encountering nulls. In your case, you want it to not break the lines.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

Locked