How to convert Plot to PiePlot3d for creating a 3d pie chart using jfreechart? - jfreechart

I am trying to create a simple 3d pie chart using jfreechart in NetBeans IDE.My code is given below :-
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("One", new Integer(10));
pieDataset.setValue("Two", new Integer(20));
pieDataset.setValue("Three", new Integer(30));
pieDataset.setValue("Four", new Integer(40));
JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset,true,true,false);
PiePlot3D plot = (PiePlot3D) chart.getPlot (); // <--error in this line
However, the last line shows the error "Incompatible types : Plot cannot be converted to piePlot3D" . Many examples i found on the internet uses the same line of code without any error. I have included all the necessary imports but still the error is shown. How can I fix this error?

You need to use the createPieChart3D() method in the ChartFactory class (you missed the '3D' on the end of the method name).
You should also look at the 3D pie charts in Orson Charts - these use real 3D projections, so they are a bit nicer. I am the author of both libraries.

Related

Displaying Parse Data to ContainerList

I want to display data from Parse in a list from GamesScores class using Container in Codename One, this is what I've tried so far and it's not showing anything nor giving any errors:
Container container = findListCont();
container.setLayout(BoxLayout.y());
container.setScrollableY(true);
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
List<ParseObject> results = (List<ParseObject>) query.find();
System.out.println("Size: " + results.size());
container.addComponent(results, f);
Please help me out, I'm a new in Codename One. If there tutorials on it, please share or anything to help me achieve the desired results.
I'm actually shocked this isn't failing. You are using the add constraint to place the object result as a constraint and you add the form object into the container...
You need to loop over the results and convert them to components to add into the layout. It also seems that you are using the old GUI builder which I would recommend against.
Generally something like this rough pseudo code should work assuming you are using a box Y layout:
for(ParseObject o : results) {
MultiButton mb = new MultiButton(o.getDisplayValue());
f.add(mb);
}
f.revalidate();

How to visualize LabelMe database using Matlab

The LabelMe database can be downloaded from http://www.cs.toronto.edu/~norouzi/research/mlh/data/LabelMe_gist.mat
However, there is another link http://labelme.csail.mit.edu/Release3.0/
The webpage has a toolbox but I could not find any database to download. So, I was wondering if I could use the LabelMe_gist.mat which has the following fields. The field names contins the labels for the images, and img perhaps contains the images. How do I display the training and test images? I tried
im = imread(img)
Error using imread>parse_inputs (line 486)
The filename or url argument must be a string.
Error in imread (line 336)
[filename, fmt_s, extraArgs, msg] = parse_inputs(varargin{:});
but surely this is not the way. Please help
load LabelMe_gist.mat;
load('LabelMe_gist.mat', 'img')
Since we had no idea from your post what kind of data this is I went ahead and downloaded it. Turns out, img is a collection of 22019 images that are of size 32x32 (RGB). This is why img is a 32 x 32 x 3 x 22019 variable. Therefore, the i-th image is accessible via imshow(img(:,:,:,i));
Here is an animation of all of them (press Ctrl+C to interrupt):
for iImage = 1:size(img,4)
figure(1);clf;
imshow(img(:,:,:,iImage));
drawnow;
end

Plotly in R Power BI

How I can create interactive R plots in Power BI (for example Plotly)? Below code doesn't return any error, but also doesn't show chart:
library(plotly)
library(ggplot2)
z = ggplot(data = dataset) + geom_point(mapping = aes(x = Console, y = Search))
ggplotly(z)
Data source:
source <- "https://cdn.rawgit.com/BlueGranite/Microsoft-R-Resources/master/power-bi/gameconsole.csv"
game.console <- read.csv(source, header = TRUE)
According to this question in Power BI's Community forums
Plotly lib is supported as part of HTML support for R powered Custom
Visuals only, not R Visuals in general currently.
Plotly can only be used if it produces an IMAGE\PNG for R visuals in
PBI. Not HTML.
For Custom Visuals we have an upcoming feature which will also enable R-based custom visuals to render as htmls.
Hope this helps.
The reason is that right now Power BI only supports render charts created by R visualization component as PNG.
Try the following:
p <- plot_ly(x = dataset$period, y = dataset$mean, name = "spline", line = list(shape = "spline"))
plotly_IMAGE(p, format = "png", out_file = "out.png")
But the problem with this is that, though rendered by plotly, the visualizations will not be interactive since its just a PNG image.
If you want to create interactive visualizations using plotly. The only way you can do is to create a custom Power BI visualization and import it to your report. See this post for a good introduction.
PowerBI only supports charts rendered as PNG while plotly format is in HTML. You can try to save the chart as PNG then print it in the R console inside PowerBI.
You first have to register a plotly account here.
After registration, on the top right corner arrow next to your account name and click on Settings -> API keys. You will be able to generate API key. Copy and paste your username and API key using this code.
Sys.setenv("plotly_username"="....")
Sys.setenv("plotly_api_key"=".....")
Then add this code in to turn the plot into png format and print it out.
fig <- plot_ly(x = dataset$Console, y = dataset$Search)
Png <- plotly_IMAGE(fig, out_file = "plotly-test-image.png")
print(Png)
As mentioned in another answer, this plot won't be interactive as plot in PowerBI. To create an interactive plot in PowerBI, you have to create a custom visual. Follow an R custom visual example here or radacad example here.

Create Fatter Candlesticks in JFreeChart

I'm developing an app that displays daily financial data, and have chosen to use JFreeChart. I was able to learn how to create a candlestick chart, but my problem lies in customization.
You see, what I'm aiming for is more along the lines of
While, so far all I've been able to manage is
.
No matter how far I zoom in, the candlesticks do not increase in width.
I'm fairly certain that somehow the thin candlesticks have something to do with being bound to a certain time range.. I've tried to remedy that but am not sure what I'm doing wrong here.
SSCE
public void showStockHistory(OHLCDataset dataset, String stockName) {
JFreeChart candleChart = ChartFactory.createCandlestickChart("History of " + stockName, "Date", "Stock Points", dataset, true);
XYPlot plot = candleChart.getXYPlot();
plot.setDomainPannable(true);
plot.setRangePannable(true);
ValueAxis domain = plot.getDomainAxis();
domain.setAutoRange(true);
NumberAxis range = (NumberAxis)plot.getRangeAxis();
range.setUpperMargin(0.0D);
range.setLowerMargin(0.0D);
range.setAutoRange(true);
range.setAutoRangeIncludesZero(false);
ChartPanel chartPanel = new ChartPanel(candleChart);
chartPanel.setMouseWheelEnabled(true);
chartPanel.setMouseZoomable(true);
getViewport().add(chartPanel);
}
Although my given example seems to have to no differing method calls from the demo in the first picture's code above, it nevertheless only shows thin candlesticks. I assume this to be some kind of bug.
However, I was able to rectify the issue as follows:
getting the renderer for the chart,
casting it to a type of CandlestickRenderer, and
setting its setAutoWidthMethod() method to CandlestickRenderer.WIDTHMETHOD_SMALLEST.
This is how you do it:
JFreeChart candleChart = ChartFactory.createCandlestickChart(
"History of " + stockName, "Date", "Stock Points", dataset, true);
XYPlot plot = candleChart.getXYPlot();
CandlestickRenderer renderer = (CandlestickRenderer) plot.getRenderer();
renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);

Changing Legend in the Future of Dynamic Data Display wpf

I have been using the Future d3 but can not figure out how to change the series legend. In the older builds the legend could be changed like:
graf = plotter.AddLineGraph(new CompositeDataSource(xSrc, plot),
new Pen(brush, 4),
new PenDescription("myText" ));
but here the function call to AddLineGraph takes an object as argument and hence one can not specify the pendescription... Please does anyone know how to do this? This question was asked before here but did not get any answers. Any help would be highly appreciated. I have spend a lot of time on this and dont want to change to any other library just because of this small issue...
The above doesn't work with recent (2016) v0.4.0.
v0.4.0 uses the following syntax:
// For access to the Legend class
using Microsoft.Research.DynamicDataDisplay.Charts;
... snip ...
LineGraph lineGraph = new LineGraph(dataSource);
lineGraph.LinePen = new Pen(Brushed.Green, 1.0);
Legend.SetDescription(lineGraph, "The line label");
plotter.Children.Add(lineGraph);
... snip ...
v0.3.0 used the following syntax:
plotter.AddLineGraph(dataSource, pen, marker, new PenDescription("The line label"));
Ref: Changing and setting the Legend (LineGraph) Future of DynamicDataDisplay
Post http://d3future.codeplex.com/discussions/635917 provided the core fix.

Resources