Avoid null in dataset for line chart - jfreechart

I'm trying to plot a LineChart using DefaultCategoryDataset and the problem I'm facing is,
when I try to plot a null value in between two values either the connection between the two points is lost (i.e the line connecting the two points doesnot appear), or else I have to skip the null value(by performing a null check on every point in DataSet) in order to connect the other two points, which results in the x-axis point not getting plotted on my graph.
For example: if I have Unit1, Unit2, Unit3 on x-axis and some values, say 10, 20, 30 for each, it works fine and plots an inclined line. But instead of 20 in Unit2, if I set null, i get only two points ploted on my graph without a line connecting those two points.
In order to get the line plotted, I have to skip the Unit2 point from my x-axis.
But what I want to do is i want to connect Unit1 to Unit3 without skipping Unit2(and its value remains null), I don't want to plot 0 instead of null.
Is there any way to do this ?

You could use two almost identical datasets but two renderers.
The first dataset should contain all data including null-values. Configure a renderer for this dataset to only draw shapes (but no lines). You'll end up with a shape for every datapoint that is not `null.
The second dataset should contain only data that is not null. Configure another renderer for this dataset to only draw lines (but no shapes). You'll get a line that just skips the null-datapoint but is continous.
Code for this could be like this:
// create your chart here...
// configure first renderer
LineAndShapeRenderer renderer = LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setBaseLinesVisible(false);
// configure second renderer
LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(true, false);
plot.setDataset(1, dataset2);
plot.setRenderer(1, renderer2);
hth,
- martin

Related

facet_wrap: using x_free scale but having only 2 different x-axis with date

I performed on three sites in two different periods messurements. Now i want to show the results using facet_wrap. Here I want to have 2 columns (first line first period, secound line secound period) and each site in a row. To have only the respective dates in the respective graph, I use x_free, resulting in the desired graph. Now I would like to delete the X axis labels in the above graphs so that the date is only visible in the last graph.
My data looks like that:
enter image description here
My code for the plots is this one:
test_data$date <- as.Date(test_data$date )
Boxes <- ggplot(test_data, aes(date, number_bats)) +
geom_col(aes(date,number_bats)) +
facet_wrap(~Box, ncol = 2, scales = "free_x")
print(Boxes)
and the resulting graph looks like that:
enter image description here
How can I now delete the dates in the first two graphs, but keep it in the last one?
Thanks for your help!
I found this package "ggh4x" with an extended facet function (facet_grid2 and facet_wrap2) which solved my problem.

Google Data Studio piechart from column with multiple values per cell

I have an excel spreadsheet from a Questionnaire. One of the questions was in checkbox format. The result of this question are held in a single column, and where the user has selected more that one answer, the answers are separated by comma's.
What devices do you own? Mobile, PC, Laptop, Tablet
So in a single cell I get 'Mobile,PC' when these two are selected.
I am using Google Data Studio to visualise the data, but stuck on how to create a graph that shows all the values individually.
At the minute I get a combination for every value. So a value of 1 for 'Mobile,PC' rather than a value for 1 'PC' and '1'Mobile.
Google Data Studio doesn't allow countif statements, so a bit lost.
I have tried to TRIM, COUNIF and REGEX but none have worked.
Count(REGEXP_MATCH(Device, "PC"))
I'm a bit lost on this, tried so many combinations. If someone can put me on the right track I would be very grateful
I don't think you'll be able to achieve that with a pie chart without changing your data source first as it needs one dimension (Device) and then one count metric which your data doesn't seem to support.
You could create 4 metrics like
SUM(
CASE
WHEN REGEXP_MATCH(Device, "PC") then 1
ELSE 0
END
)
And put them into a Stacked bar / column chart. You might need to create a dimension that has a single value to avoid having multiple bars/columns.

Why do I see "Blank" or "0" value at the begging of Stacked Column Chart in Power BI Desktop

For some reason stacked column chart displays "Blank" value even though data behind doesn't have any Blank or '0'.
And my X-axis doesnt have "Type" where I can choose between continuous or categorical:
In a data behind I have 12 months, no blank or 0 :
The (Blank) value can occur even though your underlying data set has no blank values. It is because when you have established relationship between tables, and there are other visuals or filters on the same report page, leading to a joining or filter which results in blank values.
It can be hard to pinpoint sometimes, so the easiest thing you can do is to filter it in the Visual level filters as follows:
As for the X-axis continuous or categorical type setting, it is only available when the data type is numerics or date/time. The MonthShort column you're using is just text to Power BI and it has no idea in what way it should be continuously linked. You need to use the MonthNumber or a date column if you want to achieve so.

SSRS plot value of DataSet multiple times

I have a table of data like so.
I would like to plot it on the same graph. I managed to get it to plot when putting it in a table that sorts on category "GreenTemp1", but what I would like is to plot it together on the same chart. Can anyone help me?
Edit:
I would like it to plot it like this but it does not show anything.
Add a separate series for each of the DeviceNames. The value expression for each series can be along the lines of:
=iif(Fields!DeviceName.Value = "GreenTemp1", sum(Fields!Value.Value), Nothing)
Obviously change the number for each series. Give each series its own legend name as well, and remove the category group for DeviceName.

LineChart using 2 Dataset in SSRS

I want to create a line chart using 2 set of values.First value (i.e line) will show open report and second value(i.e line) with show closed report. The x axis will show months and y axis will show number(i.e sum of report). I tried using the following expression in the values
box of chart data but i am getting a straight line.
=Sum(Fields!Count.Value, "DataSet1") for line 1
=Sum(Fields!Count.Value, "DataSet2") for line 2
I am using cube to create my Dataset.
You cannot combine two datasets in the same chart. You need to combine the data into a single dataset or use the Lookup function if you have a common field between Dataset1 and Dataset2:
http://msdn.microsoft.com/en-us/library/ee210575(SQL.105).aspx

Resources