Change axis label Color (JFreeChart) - jfreechart

Can anyone tell me how I can proceed to change the color of the axes' labels as circled below?

You can use setTickLabelPaint() and setLabelPaint() like this:
Axis domain = plot.getDomainAxis();
domain.setTickLabelPaint(Color.blue);
domain.setLabelPaint(Color.blue);
Axis range = plot.getRangeAxis();
range.setTickLabelPaint(Color.red);
range.setLabelPaint(Color.red);

Related

Axis stroke in anystock?

I am trying to change the axis stroke and axis font color in an anystock chart. I tried using the normal method for anycharts and it didn't work.
Is there a way to change these values?
You are probably looking for these methods:
https://api.anychart.com/7.14.3/anychart.core.stock.Plot#yAxis
https://api.anychart.com/7.14.3/anychart.core.stock.Plot#xAxis
Here is a sample: https://jsfiddle.net/vmgwemws/
chart.plot(0).yAxis().stroke("Red");
chart.plot(0).yAxis().ticks().stroke("Red");
chart.plot(0).yAxis().labels().fontColor("Red");
chart.plot(0).yAxis().labels().fontFamily("Courier");
chart.plot(0).xAxis().labels().fontColor("Red");
chart.plot(0).xAxis().labels().fontFamily("Courier");
chart.plot(0).xAxis().minorLabels().fontColor("Red");
chart.plot(0).xAxis().minorLabels().fontFamily("Courier");
chart.plot(0).xAxis().background("Gray 0.5");

Reseting zoom and pan when updating chart in livecharts

I'm using beto-rodriguez's livecharts for VB.NET/WPF, where I'm setting the source data in the code-behind and showing a plot when the user clicks a button.
I have enabled the zooming feature on my chart using chart.Zoom = ZoomingOptions.X. My issue here if that if I zoom to 150% and pan away from the point (0,0) for example, and I load a new plot on the same control, the zoom is not reset, as the new plot will be zoomed 150% and panned by the same value.
Is there a way to reset the chart zoom and pan every time its .Series value is reset ?
By the way, my x-axis contains dates, therefore, setting the min and max values wouldn't work.
Your answer is right, there you are forcing the range of your axis, but you can also let the chart to try to auto scale setting your axis limits to double.NaN
From the site: https://lvcharts.net/App/examples/v1/wf/Zooming%20and%20panning
cartesianChart1.AxisX[0].MinValue = double.NaN;
cartesianChart1.AxisX[0].MaxValue = double.NaN;
cartesianChart1.AxisY[0].MinValue = double.NaN;
cartesianChart1.AxisY[0].MaxValue = double.NaN;
I found the solution :
xAxis.Labels = labels
' Run these two lines every time the chart is updated
xAxis.MinValue = 0
xAxis.MaxValue = labels.Count - 1
Where xAxis is the name of my Axis control and labels is a list of strings containing the x-axis dates.

Oxyplot move all Axis labels by a custom constraint

I have a problem with OxyPlot (Windows form) Axis labels: I'd like to move y Axis label by a custom constraint, for example put all labels where indicated by arrows in the figure:
Something like Axis.LabelPadding = 10;
The Axis is a CategoryAxis with Position = AxisPosition.Left, nothing else.
How should I add a padding to each label of my axis?
To solve this problem you have to use IsTickCentered = true property when you define your CategoryAxis.
new CategoryAxis { IsTickCentered = true };

Telerik bar chart x-axis with long texts

I'm trying the telerik bar chart in my mvc application. The texts on the x-axis labels can sometimes be very long and then they overlap.
How can i solve this? can i use a tooltip for this? and how to set the tooltip text for each bar?
Thanks in advance.
You can add a tooltip by adding Tooltip(true) like so:
Html.Telerik().Chart()
.Name("chart")
.Theme("vista")
.Series( series => series
.Bar( /*data*/)
.CategoryAxis( axis => axis
.Categories( /*data*/)
.Tooltip(true)
This will display the value of the Series (x-axis) on hover.
I know you can rotate the labels on the category axis by doing something like this:
.CategoryAxis( axis =>
{
axis.Categories( /*data*/ );
axis.Labels(labels => labels.Rotation(45));//this rotates 45 degrees (you can use whatever value you want)
}
but I don't think the Label method is available on the Series. You may consider flipping the Series and the Axis (if that would still make sense for your data). You may also consider formatting (abbreviating) the x-axis labels and adding your own legend.

How to set range axis values as 0 -100 for StackedbarChart using JFreeChart?

I need to develop a Stacked bar chart usinfg JFreeChart that shows values in Percentage and Number. For percentage mode when I am setting range, the values in the range axis changes but the chart gets squished. Please guide me with your valuable suggestions.
Thanks in advance
The code
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange(0, 100);
As shown in this variation of StackedBarChartDemo2, you should specify (or convert to) percentages in the data model, not in the view. Then you can simply set the range axis label to the percent symbol, %.

Resources