Line not displaying on LineChart in Netbeans IDE - netbeans

The JFreeChart I have created is a LineChart. the problem I am having is that the line on the graph is not showing.
Can anyone tell me why this is occuring.
Here is the coding for the button:
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.setValue(100, "John B","EMP0001");
dataset2.setValue(200, "John A","EMP0003");
JFreeChart chart2 = ChartFactory.createLineChart("Comission", "Employee", "Number of Sales", dataset2, PlotOrientation.VERTICAL, false, true, true);
chart2.setBackgroundPaint(Color.YELLOW);
chart2.getTitle().setPaint(Color.RED);
CategoryPlot p2 = chart2.getCategoryPlot();
p2.setRangeGridlinePaint(Color.BLUE);
ChartFrame frame2 = new ChartFrame("Employee Comission", chart2);
frame2.setVisible(true);
frame2.setSize(450,350);
This is what happens when the line chart is created:
Line chart without line displaying on chart
Please could someone help just indicate to me where the possible problem lies.

In order to show a line you need to have two data items that have the same value for the rowKey and different values for the column key.
if you change the data to:
dataset2.setValue(100, "John A","EMP0000");
dataset2.setValue(200, "John A","EMP0001");
dataset2.setValue(300, "John B","EMP0002");
dataset2.setValue(400, "John B","EMP0004");
then in plots :
Notice that the "John A" values are red and the "John B" values are blue and
the red and blue do not connect. The column values are printed along the bottom.

Related

How to plot horizontal bars / columns / lines on timeseries data with HighStock?

I'd like to plot horizontal bars and/or lines on timeseries data with highstock, however I'm not able to identify the corresponding series type and how to feed the data in?
Is possible? If yes, how?
A screenshot of what I may imagine as outcome:
Data could be something similar eg:
[
{
"start": 1610969882000, // epoche time in ms
"end": 1624016282000,
"text": "Bar on timeseries",
"style": "bar",
"level": 1 // y-Axis height where to show
},
{
"start": 1613648282000,
"end": 1618745882000,
"text": "Line on timeseries",
"style": "line",
"level": 8
}
]
I did find column-range charts which seem to work with line charts, however I struggled overlaying this on a highstock timeseries chart, adding a label on top or making it a line with tooltip. Adding to highstock always ends up throwing an error "Script error."
Thx a lot in advance, I really appreciate your expertise!
Use xrange series type:
series: [{
type: 'xrange',
...
}]
Live demo: https://jsfiddle.net/BlackLabel/o9ks1efd/
API Reference: https://api.highcharts.com/highstock/series.xrange

Custom Chart Fill / Pattern

I am struggling to define the fill color and fill pattern of a stacked column chart. To clarify, I have one series value, and two series groupings (RepairLevel, InProcess).
In the fill color expression I have:
=Switch( Fields!RepairLevel.Value = "Major", "red"
,Fields!RepairLevel.Value = "Mid", "orange"
,Fields!RepairLevel.Value = "Minor", "yellow"
,Fields!RepairLevel.Value = "NA", "grey"
,Fields!RepairLevel.Value = "Unspecified", "light grey" )
In the fill pattern expression I have entered:
=Switch( Fields!InProcess.Value = True, "BackwardDiagonal"
,Fields!InProcess.Value = False, "None" )
It seems that the fill color is working properly. However, the fill pattern is not -- I am getting various fill patterns. Thanks in advance for any insights, I truly appreciate your time.

Use a different legend to dimension on VizFrame Chart

I would like to show a concatenation fields as axis labels on a chart, is this possible?
So, for the given data:
{d: [ {
"Category": "Vendor",
"BusinessProcess": "Create Manufacture's Part",
"Scenario": "Create Vendor - General Data",
"Role": "General",
"Average_Duration_Days": 43,
"Row_ID": "4"
},
{
"Category": "Vendor",
"BusinessProcess": "Create Vendor - General Data",
"Scenario": "Create Vendor - General Data",
"Role": "General",
"Average_Duration_Days": 38,
"Row_ID": "5"
}
I would like to use Average_Duration_Days as the measure. I would also like to show both rows and the for the label for the row show something like BusinessProcess + Role.
Is it possible to use Row_ID as the dimension and then a concatenation of the other fields as the axis label?
Here's a simple code bin:
http://jsbin.com/yifejik/edit?js,output
You can use the attribute 'value' as the selector for your Bars and 'displayValue' as the label. I used a formatter to combine two values.
See jsbin:
http://jsbin.com/wumozevimi/edit?js,output
You could also add a second dimension and include it into your categoryAxis-Feed.

google charts annotations show right side of point

I am using google charts for plotting a graph
How can I show annotation of the point at right-hand-side of the point but it showing on the top of point
http://i.stack.imgur.com/UHhQH.png
I want it like as follow
http://i.stack.imgur.com/lUBcq.png
Please any one help me out
You can actually change the position of the annotations, by using css tranform.
You should first get a handle to the anntation text, if you want to change all the text, then you can use the text tag name in css
text {
transform: translate(10px, 30px);
}
I was able to adjust annotations to the right by doing 2 things:
1) Entered some white spaces (\u00A0 is white space) and a long dash (—) on the left side of the desired annotation.
2) Added stem length of -3.
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('string', 'Model');
dataTable.addColumn('number', 'T');
dataTable.addColumn({type:'string', role:'annotation'});
dataTable.addRows([
['ABC',30,'\u00A0\u00A0\u00A0\u00A0 — X'],
['DEF',20,'\u00A0\u00A0\u00A0\u00A0 — Y'],
['GHI',10,'\u00A0\u00A0\u00A0\u00A0 — Z'],
]);
var options = {
1: {annotations: {stem: {length: -3}}
};

Change tooltip data in Google Charts

I have column google charts. (using https://www.google.com/jsapi)
Vertical axis for count of bananas(for example)
Horizontal axis for dates
so, each my column tooltip looks like:
20.02.2011
Bananas: 3
I need to replace 20.02.2011 on some my text on each column.
Is it possible?
UPD
I need to replace 20.02.2011 on some my text on each column.
But dates on Horizontal axis should stay as they are.
The best way to do it without changing your actual data points is via the tooltip option. As an example copy the following code to google's visualization playground.
function drawVisualization() {
data = new google.visualization.DataTable()
data.addColumn('string', 'Date');
data.addColumn('number');
data.addColumn({type:'string',role:'tooltip'});
data.addRow();
base = 10;
data.setValue(0, 0, 'Datapoint1');
data.setValue(0, 1, base++);
data.setValue(0, 2, " This is my tooltip1 ");
data.addRow();
data.setValue(1, 0, 'Datapoint2');
data.setValue(1, 1, base++);
data.setValue(1, 2, "This is my second tooltip2");
// Draw the chart.
var chart = new google.visualization.BarChart(document.getElementById('visualization'));
chart.draw(data, {legend:'none', width:600, height:400});
}
One option is to change the horizontal axis with the text that you want.
For ex.
In this sample code http://code.google.com/apis/ajax/playground/?type=visualization#bar_chart
Chart URL
If you want to replace year with your custom text then change
var years = [2003, 2004, 2005, 2006, 2007, 2008];
to either
var years = ["a", "b", "c", "d", "e", "f"];
or
var years = ["2003:a", "2004:b", "2005:c", "2006:d", "2007:e", "2008:f"];