The code to draw a bar chart as follows:
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setXLabels(4);
renderer.setYLabels(4);
ChartLabel chartLabel = getChartLabelfromString(dateL);
for (int i=0; i<chartLabel.labelIdxs.size(); i++){
renderer.addXTextLabel(chartLabel.labelIdxs.get(i),chartLabel.labelStrs.get(i));
}
BarChart chart = new BarChart(buildBarDataset(titles, valueDDL), renderer, BarChart.Type.DEFAULT);
chartLabel.labelIdxs.size() = 4
There are two strange values in the xlabels marked as red color. How do I remove the values 5,10 in the Xaxis?
Barchart Sample Code Output with labels A B C D
There are a number of ways to remove a symbol from your Watchlist.
Using the Links Column
Click on the Links icon.
Select "Delete from Watchlist". The symbol is immediately removed.
It seems you're setting the font size to be relatively large with long labels so they override each other. You can set the angle of the text to fit longer text or you can shrink the font size but there's a limit to what can physically fit under a chart. I suggest just using the month denominator in the labels.
There might be other options since the renderer class includes a lot of them.
Related
I'm using ChartJS to display multiple charts on a page.
Each chart has a different dataset, and different labels (some have short labels, some have long labels).
Currently the width of the actual 'data-part' (the part of the chart showing e.g. Bars) depends on how much space the labels take. I would like to make all charts have a fixed size for the data-part, and let the labels take up the remaining size.
See for example the following screenshot. Here I display 2 charts, but the actual data-part is different for both, because one has shorter labels than the other.
What I would like is to set for example a fixed width of 400px for the data-part, and let the labels take the remaining space left on the page. That way the charts would be aligned perfectly above each other.
Even better would be if I could set that for each chart the data-part takes a percentage of the width (e.g. 70%), so the labels take the rest (30%).
I have checked the ChartJS documentation, but the only I can find it setting the width for the entire chart-component.
Cheeky solution - you can add a dummy chart before your charts having the same labels.
Let's call this dummy chart as chart D and your main chart as chart M.
In M, you would fix it's width and hide the labels by writing in options -
scales: {y: {ticks: {display: false}}}
Now you have a fixed data width.
In D, you would just display the labels and hide the data part (hiding grid lines, legend, title, etc.).
So now you have two charts side-by-side, one is displaying just the labels and the other displaying the bars, just need to position it in such a way that no matter how long the label is, it does not overlap with M. Repeat the step similarly for all charts and have the same width for M1,M2,M3,...
This is a solution that seemed to work for me.
I'd like to highlight a single column in a WinForm StackedColumn Chart. As examples, I'm seeing how to put borders around the individual DataPoints in each Series displayed in the column and put an ArrowAnnotation pointing at one of the DataPoints, but I don’t see a way to highlight the column as a whole. For example, it would be great to have the column expand to say twice the width of the other columns and/or have a different backcolor (including the empty areas above and below the DataPoints). Is it possible to do what I want and, if so, how? C# examples are preferable but not necessary.
Thanks. Steve
You could dim every other column, using BackHatchStyle = ChartHatchStyle.Percent50 and BackSecondaryColor = Color.Black. This will make your chosen column appear brighter/highlighted.
Here's an example:
int highlightColumnIndex = 0; // Set the highlighted column here!
foreach (Series cs in chart1.Series) {
foreach (DataPoint dp in cs.Points) {
dp.BackSecondaryColor = Color.Black;
dp.BackHatchStyle = ChartHatchStyle.Percent50;
}
cs.Points[highlightColumnIndex].BackHatchStyle = ChartHatchStyle.None;
}
Change chart1 to your chart's name, and change highlightColumnIndex to match the index of the column you want to highlight.
Hope this helps :)
I wonder what's the best way of getting a text bounding box with FreeType 2?
To get the linespace bounding box width, I iterate over all the characters of the text and get it's advance and kearning:
FT_Face face = ...;
text_bbox_width = 0;
while (*p_text)
{
...
FT_Get_Kerning(...);
text_bbox_width += (face->glyph->advance.x + kerning.x) >> 6;
}
How to get linespace bounding box height? Is it necessary to iterate or can it be obtained using font face data? I.e:
text_bbox_height = (face->ascender - face->descender) >> 6
Good news: you do not need to iterate over the characters in each of your strings. You can use face->size->metrics->height, as described in 3. Global glyph metrics of http://www.freetype.org/freetype2/docs/tutorial/step2.html. Note the warnings on using ascender and descender.
Do not mistake this height for the actual pixel bounding box. Individual glyphs may stick out of this box. You can use this line height to get an even spacing over multiple lines in the same text block. To get 'larger' or 'smaller' spacing, you can multiply this value with a constant, such as 1.5 or 2.0 for "double line spacing".
I'm guessing that the value of height that Freetype calculates is the "normal" or "optimal" line spacing for a certain font.
Is it possible to use different fonts or font sizes in the title of a JFreeChart object?
Using:
chart.getTitle().setFont(new Font("Tahoma", Font.PLAIN, 16));
allows one to set the font but I am trying to create a bold, large font-size title followed by an explanatory sub-title with smaller font size on the line below.
E.g. something like: "Intensive Care Infections / data from 2008-01-01 up to 2012-12-31"
Any other way to achieve this effect, if not possible in the title object?
You can add one or many subtitles using the addSubtitle() method in the JFreeChart class. The title is always drawn first, then the subtitles are drawn (by index order). Note that the legend is added to the chart as a "subtitle", so depending on the position you may want to insert your real subtitle at index 0 so that it is positioned and drawn before the legend.
I want to generate 12 different visible Brush Colors in WPF in my code behind and the number of colors which is initially 12 may vary as the application evolves i.e. I want to generate as many different visible Brush Colors depending on a given count?
I would explain it a little more:
I am creating Rectangles in a for loop and for each rectangle created at run time I have to assign a Fill Color e.g.
for (i=0; i<12; i++)
{
Rectangle rect = new Rectangle();
rect.Fill = <I want to assign a unique visible color>;
rect.Stroke = Brushes.Black;
rect.StrokeThickness = 1;
}
What you probably need is an RGB to HSL, and HSL to RGB converter. You can then divide the total hue (usually represented as degrees in a circle, but sometimes a percent value) by the number of colors required. Incrementing the hue value by the segment amount should produce the most differentiated colors possible.
Most examples use the WinForms Color object since it was able to provide H S and L values. There are lots of online examples:
https://web.archive.org/web/20141023005253/http://bobpowell.net/RGBHSB.aspx
how to use HSL in Asp.net
Brushes can be assigned colors, This SO question should help you in getting the colors, and then assign them each time you create a new brush for any number of brushes.
Just for reference:
Brush Class
Brushes class
Use a random number generator to create the RGB triple for the colour. Save it in a list. Then the next time round the loop check the newly generated colour against the list. If it's not in the list use it, if it is choose again.
Potentially this could run into trouble if you have a lot of colours so you're more and more likely to hit an existing colour, but for 12 (or so) colours it should be OK.
Alternatively create a list of 100's of colours and remove each one from the list when it's picked randomly. This will ensure you don't get any clashes but would require you extend the list if you needed more colours.