JavaFx adding a text label on top of StackedBarChart - javafx-2

After Search
I found this sample how to display bar value on top of bar javafx, But that when bar separated on the category axis so each category data has a single bar and Listener can be added to that data (Category).
But with StackedBarChart each category consists of StackedBar.
I try that code simple based on the #jewelsea code.
That solution work prefect if all series are symmetric and contain all the categories.
But with non-symmetric series
ObservableList<StackedBarChart.Series> barChartData = FXCollections.observableArrayList(
new StackedBarChart.Series("Region 1", FXCollections.observableArrayList(
new StackedBarChart.Data(years[0], 567d),
new StackedBarChart.Data(years[1], 1292d),
new StackedBarChart.Data(years[2], 1292d))),
new StackedBarChart.Series("Region 2", FXCollections.observableArrayList(
new StackedBarChart.Data(years[0], 956),
new StackedBarChart.Data(years[1], 1665),
new StackedBarChart.Data(years[2], 2559))),
new StackedBarChart.Series("Region 3", FXCollections.observableArrayList(
new StackedBarChart.Data(years[0], 1154),
//new StackedBarChart.Data(years[1], 1927),// series names Region 3(which is the last series on the chart data) doesn't exist category years[1] "2008".
new StackedBarChart.Data(years[2], 2774))));
We will miss Text on top of category 2008.
Any help are welcome.

It's missing because you comment it out:
//new StackedBarChart.Data(years[1], 1927),// series names Region 3(which is the last series on the chart data) doesn't exist category years[1] "2008".
That second parameter is the "1927" title. This is technically the Y-Axis parameter. You need to keep that line in order to show that "1927". Check out the API:
http://docs.oracle.com/javafx/2/api/javafx/scene/chart/StackedBarChart.html
You may need to put your "titles" up another way. Use a text class and add it on top of the StackedBarChart.Series objects.

Related

Displaying multiple values in Altair/Streamlit tooltips on a bar chart

My DataFrame looks similar to this:
name
reached points
Jose Laderman
13
William Kane
13
I am currently displaying the aggregated count of students reached points of an assignment on an Altair bar chart within Streamlit like this:
brush = alt.selection(type='interval', encodings=['x'])
interactive_test = alt.Chart(df_display_all).mark_bar(opacity=1, width=5).encode(
x= alt.X('reached points', scale=alt.Scale(domain=[0, maxPoints])),
y=alt.Y('count()', type='quantitative', axis=alt.Axis(tickMinStep=1), title='student count'),
).properties(width=1200)
upper = interactive_test.encode(
alt.X('reached points', sort=alt.EncodingSortField(op='count', order='ascending'), scale=alt.Scale(domain=brush, domainMin=-0.5))
)
lower = interactive_test.properties(
height=60
).add_selection(brush)
concat_distribution_interactive = alt.vconcat(upper, lower)
Which produces this output and everything looks fine
The information I want my tooltip to show is a list of students that reached the specific amounts of reached points I'm hovering over. When adding something like:
tooltip='name'
the way my bar chart seems to display values has now been altered to this
When adding something like
tooltip='reached points'
The data seems to be displayed normally but without a tooltip that gives me the necessary information. Is it possible to display tooltip data that isn't used in my x or y axis but still part of the DataFrame I'm putting into the chart?

Bumbling around plotting two sets of seasonal data on the same chart

I have series of monthly inventory data since 2017.
I have a series of inventory_forecasts since Dec2018
I am trying to plot the inventory data on a monthly-seasonal basis, and then overlay the inventory_forecasts of Jan2019 through Dec2019.
The dataframe looks like:
The first way I tried to make the chart does show all the data I want, but I'm unable to control the color of the inventory_zj line. Its color seems to be dominated by the color=year(date):N of the alt.Chart I configured. It is ignoring the color='green' I pass to the mark_line()
base = alt.Chart(inv.loc['2000':].reset_index(), title=f"usa total inventory").mark_line().encode(
x='month',
y="inventory",
color="year(date):N"
)
#this ignores my 'green' color instruction, and marks it the same light blue 2019 color
joe = base.mark_line(color='green').encode(
alt.Y('inventory_zj', scale=alt.Scale(zero=False), )
)
base+joe
I tried to use a layering system, but it's not working at all -- I cannot get it to display the "joe" layer
base = alt.Chart(inv.loc['2000':].reset_index(), title=f"usa total inventory").encode(
x='month(date)'
)
doe = base.mark_line().encode(
alt.Y('inventory', scale=alt.Scale(zero=False), ),
color="year(date):N"
)
joe = base.mark_line(color="green").encode(
alt.Y('inventory_zj', scale=alt.Scale(zero=False), ),
)
#looks identical to the first example
alt.layer(
doe, joe
).resolve_scale(
y='shared'
).configure_axisLeft(labelColor='black').configure_axisRight(labelColor='green',titleColor='green')
#independent shows a second y-axis (which is different from the left y-axis) but no line
alt.layer(
doe, joe
).resolve_scale(
y='independent'
).configure_axisLeft(labelColor='black').configure_axisRight(labelColor='green',titleColor='green')
I feel like i must be trying to assemble this chart in a fundamentally wrong way. I should be able to share teh same left y-axis, have the historic data colored by its year, and have a unique color for the 2019-forecasted data. But I seem to be making a mess of it.
As mentioned in the Customizing Visualizations docs, there are multiple ways to specify things like line color, with a well-defined hierarchy: encodings override mark properties, which override top-level configurations.
In your chart, you write base.mark_point(color='green'), where base contains a color encoding which overrides the mark property. If you don't derive the layer from base (so that it does not have a color encoding), then the line will be green as you hoped. Something like this:
base = alt.Chart(inv.loc['2000':].reset_index(), title=f"usa total inventory")
inventory = base.mark_line().encode(
x='month',
y="inventory",
color="year(date):N"
)
joe = base.mark_line(color='green').encode(
x='month',
y=alt.Y('inventory_zj', scale=alt.Scale(zero=False))
)
inventory + joe

Flot pie chart - label formatter function parameters?

Posted this on google group, but post seems to have disappeared so will try here.
I have a data array which I use to populate the flot chart series data and all works fine. I now want to make both the legend and related segment clickable so I can "drill down" to more detail in the pie chart and have another pie chart show with a breakdown of that segment's data.
The label formatter custom function is obviously where to do this, but it only accepts label and series and the series doesn't seem to contain the index of the position in the array of each series object as it passes through the label formatter function.
I'm trying to do something like:
function labelFormatter(label, series)
return '<a href="#" onclick="myfunction(" + series.index + ")>" + label + "</a>"
}
...so that I can pass the clicked segment details. I suppose I could just use the label passed and then search through the original data array for a match and use that index position to work out the item clicked, but it seems a bit long winded.
Am I missing some functionality here or is it just not possible to do it the way I'm trying?
The legend by default shows series in the same order as you provided them. You can therefore use a regular jQuery loop to turn them into links, or simply add click listeners.
$.each(".legend tr", function(i, row) {
addDrillDownListener(row, series[i]);
});
Working with the pie slices themselves is even easier, since the hover and click callbacks receive an object with a seriesIndex attribute.

libgdx table lays out components only in bottom right area

I'm using a Table to add some Labels to a stage. For some reason it adds it to the bottom right corner instead of the top left. Any ideas about how I can lay out the components correctly?
int dialogWidth = 450;
int dialogHeight = 650;
Label label1 = new Label("MUSIC:", skin);
Label label2 = new Label("SOUND EFFECTS:", skin);
Label label3 = new Label("JUMP SPEED:", skin);
TextButton btn1 = new TextButton("whatever", skin);
final Dialog dialog = new Dialog("Properties", skin);
dialog.setSize(dialogWidth, dialogHeight);
dialog.setX(Helper.RESOLUTION_X_CENTER-dialogWidth/2);
dialog.setY(Helper.RESOLUTION_Y_CENTER-dialogHeight/2);
Table t = new Table();
t.setBounds(0, 0, dialogWidth, dialogHeight);
t.add(label1);
t.row();
t.add(label2);
t.add(btn1);
t.row();
t.add(label3);
dialog.add(t);
stage.addActor(dialog);
Fix 1:
Solution: Remove the following line
t.setBounds(0, 0, dialogWidth, dialogHeight);
Reason: Don't use setBounds yourself. Let the layoutmanager handle it.
Fix 2:
Solution: Replace the following line
dialog.add(t);
with
dialog.getContentTable().add(t).expand().left().top();
Reason: Dialog is itself a Table which contains 3 components viz Title, ContentTable, ButtonTable.
Your code was adding the new Table in the row of ButtonTable (last row hence at bottom) after ButtonTable (hence right).
The updated code adds it to the Content Table where it is supposed to be.
Refer to https://github.com/EsotericSoftware/tablelayout to understand reason behind
expand().left().top();
Lastly, to debug any Table related issue, consider using debug lines (explained in the same link)
Hope this helps.

How to change the color of an individual item of the plot chart in Flex?

I am creating a plot chart in Flex that takes in an array collection. The array collection has the following format:
var provinces:ArrayCollection = new ArrayCollection (
{PROVINCE:"Ha Noi", Male:50000, Female:20000},
{PROVINCE:"Ha Tay", Male:100000, Female:10000},
{PROVINCE:"Quang Ninh", Male:75250, Female:45021},
{PROVINCE:"Hai Phong", Male:10000, Female:25000});
I want to use different colors to display different provinces on the plot chart. Moreover, I want to create a legend for different provinces. Would anyone know how to do it? Some code example would be great.
Thank you.

Resources